/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store() { if (Session::get('level') == '1' && Session::get('fingerprint') == md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR'])) { $postData = Input::All(); $messages = ['company.required' => 'กรุณากรอก']; $rules = ['company' => 'required']; $validator = Validator::make($postData, $rules, $messages); if ($validator->fails()) { return Redirect::route('company.create')->withInput()->withErrors($validator); } else { $data = Request::all(); $company = new Company(); $company->company = $data['company']; $company->address = $data['address']; $company->mobile = $data['mobile']; $company->email = $data['email']; DB::transaction(function () use($company) { $company->save(); }); Session::flash('savedata', save_data); return Redirect::to('company'); } } else { return Redirect::to('/'); } }
public function actionCompany() { $company = Company::find()->one(); if (empty($company)) { $company = new Company(); $company->vat = 0; $company->logo = ''; } $post = Yii::$app->request->post(); if (!empty($post)) { if (!empty($_FILES['Company']['name']['logo'])) { $tmp_name = $_FILES['Company']['tmp_name']['logo']; $name = $_FILES['Company']['name']['logo']; if (file_exists('upload/' . $name)) { unlink('upload' . $name); } if (move_uploaded_file($tmp_name, 'upload/' . $name)) { $company->logo = $name; } } $company->name = $post['Company']['name']; $company->tax_code = $post['Company']['tax_code']; $company->tel = $post['Company']['tel']; $company->website = $post['Company']['website']; $company->address = $post['Company']['address']; $company->vat = $post['Company']['vat']; if ($company->save()) { $session = new Session(); $session->setFlash('message', 'บันทึกรายการแล้ว'); return $this->redirect(['company']); } } return $this->render('//config/company', ['company' => $company]); }
/** * Creates a new Company model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Company(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Save data from new company form. * * @author [Abdullah Alansari] [<*****@*****.**>] * @since [v1.8] * @return Redirect */ public function postCreate() { $company = new Company(); $company->name = e(Input::get('name')); if ($company->save()) { return redirect()->to('admin/settings/companies')->with('success', trans('admin/companies/message.create.success')); } else { return redirect()->back()->withInput()->withErrors($company->getErrors()); } }
public function actionDoadd() { $company = new Company(); $company->c_name = $_POST['c_name']; $company->c_show = $_POST['c_show']; $company->c_desc = $_POST['c_desc']; if ($company->save()) { echo $this->success("添加成功", "index.php?r=company", '1'); } else { echo $this->error("添加失败", "index.php?r=company", '1'); } }
/** * Creates a new Company model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->user->identity->type == 'normal') { return $this->redirect(['company/']); } $model = new Company(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->company_id]); } else { return $this->render('create', ['model' => $model]); } }
private function createCompany($addressID) { $company = new Company(); $company->created_at = date("Y-m-d H:i:s"); $company->name = $this->email; $company->comment = ""; $company->phone = ""; $company->twenty_four_hours = 0; $company->active = 1; $company->status_d = 0; $company->address_id = $addressID; $company->save(); return $company->id; }
public function actionCompany() { $model = new Company(); if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { $model->is_sponsor = 0; $model->is_organisator = 0; $model->save(); Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.'); return $this->refresh(); } } return $this->render('company', ['model' => $model]); }
private function openCompanies($count = 100) { print_r("Open companies. Count: " . $count . "..."); $this->faker->unique(true); $buildings = Building::find()->asArray()->all(); $building_ids = ArrayHelper::getColumn($buildings, 'id'); $building_ids_length = count($building_ids) - 1; for ($i = 0; $i < $count; $i++) { $company = new Company(); $company->title = $this->faker->unique()->company; $company->building_id = $building_ids[mt_rand(1, $building_ids_length)]; $company->save(); } print_r("DONE" . PHP_EOL); }
public function create_submit() { $data = \Request::all(); $company = new Company(); $company->name = $data['name']; if (isset($data['image'])) { $file_name = \Common::get_img_filename($data['image']); \Common::make_square_img($file_name, 140); $res = \Common::s3_upload($file_name, 'company/'); if ($res['success']) { $company->ci = $res['filename']; } } $company->status = $data['status_group']; $company->save(); return \Redirect()->action('CompanyController@index'); }
public function create($firstName = '', $lastName = '', $email = '', $password = '') { $company = new Company(); $company->utm_source = Input::get('utm_source'); $company->utm_medium = Input::get('utm_medium'); $company->utm_campaign = Input::get('utm_campaign'); $company->utm_term = Input::get('utm_term'); $company->utm_content = Input::get('utm_content'); $company->save(); $account = new Account(); $account->ip = Request::getClientIp(); $account->account_key = str_random(RANDOM_KEY_LENGTH); $account->company_id = $company->id; // Track referal code if ($referralCode = Session::get(SESSION_REFERRAL_CODE)) { if ($user = User::whereReferralCode($referralCode)->first()) { $account->referral_user_id = $user->id; } } if ($locale = Session::get(SESSION_LOCALE)) { if ($language = Language::whereLocale($locale)->first()) { $account->language_id = $language->id; } } $account->save(); $user = new User(); if (!$firstName && !$lastName && !$email && !$password) { $user->password = str_random(RANDOM_KEY_LENGTH); $user->username = str_random(RANDOM_KEY_LENGTH); } else { $user->first_name = $firstName; $user->last_name = $lastName; $user->email = $user->username = $email; if (!$password) { $password = str_random(RANDOM_KEY_LENGTH); } $user->password = bcrypt($password); } $user->confirmed = !Utils::isNinja(); $user->registered = !Utils::isNinja() || $email; if (!$user->confirmed) { $user->confirmation_code = str_random(RANDOM_KEY_LENGTH); } $account->users()->save($user); return $account; }
public function readIni() { //new company // // //get perm from ini $encoding = "windows-1255"; //$encoding="ibm862"; $ini = $this->iniFile; if ($fp = fopen($ini, 'r')) { while ($line = fgets($fp)) { @($line = iconv($encoding, "UTF-8//IGNORE", $line)); //$line=utf8_encode($line); $type = substr($line, 0, 4); //$obj=$this->readline($line,$type); $obj = true; if (!$obj) { //$suc[$type]--; } else { //foreach ($obj as &$value) // if ($encoding=="ibm862") // $value = iconv("ISO-8859-8", "UTF-8", hebrev(iconv("UTF-8", "ISO-8859-8", $value))); if ($type == 'A000') { //Acc Haeder /* Account Import */ $comp = new Company(); $comp->string = Yii::$app->dbMain->dsn; $comp->user = Yii::$app->dbMain->username; $comp->password = Yii::$app->dbMain->password; /* $obj["type"]=(int)$obj["type"]+50; if(isset($accTypeIndex[$obj["type"]])) $accTypeIndex[$obj["type"]]=$accTypeIndex[$obj["type"]].",".$obj["name"]; else $accTypeIndex[$obj["type"]]=$obj["typedesc"].":".$obj["name"]; unset($obj["typedesc"]); */ //1405 acc type code //1406 acc type name //print_r($obj);//Yii::$app->end(); //$comp->createDb(); $comp->save(); $this->companyId = $comp->id; $comp->readLine($line, $type); $this->clearCompany(); //$accIndex[$obj["id"]]=$acc->save(); //get new acc index save old //$this->companyId=$comp->id; //echo $this->companyId; //Yii::$app->end(); unset($comp); } } } } }
public function jqgrid(Request $request) { // return dd($request->all()); if (Auth::check()) { if (User::isSuperAdmin()) { $validate = \Validator::make($request->all(), ['name' => 'required']); if ($validate->passes()) { switch ($request->input('oper')) { case 'add': $audit = new AuditsController(); $active = 'Inactive'; if ($request->input('active') == 'true') { $active = 'Active'; } $company = new Company(); $company->name = $request->input('name'); $company->save(); $audit->store('company', $company->id, null, 'add'); return $msg = ['success' => true, 'msg' => "your Company:cl{$company->id} Added successfully"]; break; case 'edit': $company_id = $request->input('id'); $company = Company::find($company_id); if ($company) { $data = array(); $audit = new AuditsController(); if ($company->name != $request->input('name')) { array_push($data, 'Name'); array_push($data, $company->name); array_push($data, $request->input('name')); $company->name = $request->input('name'); } $audit->store('company', $company_id, $data, 'edit'); $company->save(); return $msg = ['success' => true, 'msg' => "your Company:cl{$company_id} Saved saved successfully"]; } break; } } } return "don't have permission"; } return Redirect::to(url('user/login')); }
/** * Fetch an existing company, or create new if it doesn't exist * * @author Daniel Melzter * @since 3.0 * @param $asset_company_name string * @return Company */ public function createOrFetchCompany($asset_company_name) { foreach ($this->companies as $tempcompany) { if (strcasecmp($tempcompany->name, $asset_company_name) == 0) { $this->log('A matching Company ' . $asset_company_name . ' already exists'); return $tempcompany; } } $company = new Company(); $company->name = $asset_company_name; if (!$this->option('testrun')) { if ($company->save()) { $this->companies->add($company); $this->log('Company ' . $asset_company_name . ' was created'); return $company; } else { $this->log('Company', $company->getErrors()); } } else { $this->companies->add($company); return $company; } }
public function actionCreate() { //only admin $model = new Company(); $model->string = Yii::$app->dbMain->dsn; $model->user = Yii::$app->dbMain->username; $model->password = Yii::$app->dbMain->password; //$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; //$model->prefix=substr(str_shuffle($chars),0,4)."_"; if ($model->save()) { $database = Company::findOne($model->id); Yii::$app->session['company'] = $model->id; //redierct to settings. return $this->redirect(array('settings/admin')); } return $this->render('create', array('model' => $model)); }
/** * Execute the console command. * * @return mixed */ public function fire() { $filename = $this->argument('filename'); if (!$this->option('testrun') == 'true') { $this->comment('======= Importing Assets from ' . $filename . ' ========='); } else { $this->comment('====== TEST ONLY Asset Import for ' . $filename . ' ===='); $this->comment('============== NO DATA WILL BE WRITTEN =============='); } if (!ini_get("auto_detect_line_endings")) { ini_set("auto_detect_line_endings", '1'); } $csv = Reader::createFromPath($this->argument('filename')); $csv->setNewline("\r\n"); $csv->setOffset(1); $duplicates = ''; // Loop through the records $nbInsert = $csv->each(function ($row) use($duplicates) { $status_id = 1; // Let's just map some of these entries to more user friendly words // User's name if (array_key_exists('0', $row)) { $user_name = trim($row[0]); } else { $user_name = ''; } // User's email if (array_key_exists('1', $row)) { $user_email = trim($row[1]); } else { $user_email = ''; } // User's email if (array_key_exists('2', $row)) { $user_username = trim($row[2]); } else { $user_username = ''; } // Asset Name if (array_key_exists('3', $row)) { $user_asset_asset_name = trim($row[3]); } else { $user_asset_asset_name = ''; } // Asset Category if (array_key_exists('4', $row)) { $user_asset_category = trim($row[4]); } else { $user_asset_category = ''; } // Asset Name if (array_key_exists('5', $row)) { $user_asset_name = trim($row[5]); } else { $user_asset_name = ''; } // Asset Manufacturer if (array_key_exists('6', $row)) { $user_asset_mfgr = trim($row[6]); } else { $user_asset_mfgr = ''; } // Asset model number if (array_key_exists('7', $row)) { $user_asset_modelno = trim($row[7]); } else { $user_asset_modelno = ''; } // Asset serial number if (array_key_exists('8', $row)) { $user_asset_serial = trim($row[8]); } else { $user_asset_serial = ''; } // Asset tag if (array_key_exists('9', $row)) { $user_asset_tag = trim($row[9]); } else { $user_asset_tag = ''; } // Asset location if (array_key_exists('10', $row)) { $user_asset_location = trim($row[10]); } else { $user_asset_location = ''; } // Asset notes if (array_key_exists('11', $row)) { $user_asset_notes = trim($row[11]); } else { $user_asset_notes = ''; } // Asset purchase date if (array_key_exists('12', $row)) { if ($row[12] != '') { $user_asset_purchase_date = date("Y-m-d 00:00:01", strtotime($row[12])); } else { $user_asset_purchase_date = ''; } } else { $user_asset_purchase_date = ''; } // Asset purchase cost if (array_key_exists('13', $row)) { if ($row[13] != '') { $user_asset_purchase_cost = trim($row[13]); } else { $user_asset_purchase_cost = ''; } } else { $user_asset_purchase_cost = ''; } // Asset Company Name if (array_key_exists('14', $row)) { if ($row[14] != '') { $user_asset_company_name = trim($row[14]); } else { $user_asset_company_name = ''; } } else { $user_asset_company_name = ''; } // A number was given instead of a name if (is_numeric($user_name)) { $this->comment('User ' . $user_name . ' is not a name - assume this user already exists'); $user_username = ''; $first_name = ''; $last_name = ''; // No name was given } elseif ($user_name == '') { $this->comment('No user data provided - skipping user creation, just adding asset'); $first_name = ''; $last_name = ''; //$user_username = ''; } else { $user_email_array = User::generateFormattedNameFromFullName($this->option('email_format'), $user_name); $first_name = $user_email_array['first_name']; $last_name = $user_email_array['last_name']; if ($user_email == '') { $user_email = $user_email_array['username'] . '@' . config('app.domain'); } if ($user_username == '') { if ($this->option('username_format') == 'email') { $user_username = $user_email; } else { $user_name_array = User::generateFormattedNameFromFullName($this->option('username_format'), $user_name); $user_username = $user_name_array['username']; } } } $this->comment('Full Name: ' . $user_name); $this->comment('First Name: ' . $first_name); $this->comment('Last Name: ' . $last_name); $this->comment('Username: '******'Email: ' . $user_email); $this->comment('Category Name: ' . $user_asset_category); $this->comment('Item: ' . $user_asset_name); $this->comment('Manufacturer ID: ' . $user_asset_mfgr); $this->comment('Model No: ' . $user_asset_modelno); $this->comment('Serial No: ' . $user_asset_serial); $this->comment('Asset Tag: ' . $user_asset_tag); $this->comment('Location: ' . $user_asset_location); $this->comment('Purchase Date: ' . $user_asset_purchase_date); $this->comment('Purchase Cost: ' . $user_asset_purchase_cost); $this->comment('Notes: ' . $user_asset_notes); $this->comment('Company Name: ' . $user_asset_company_name); $this->comment('------------- Action Summary ----------------'); if ($user_username != '') { if ($user = User::MatchEmailOrUsername($user_username, $user_email)->whereNotNull('username')->first()) { $this->comment('User ' . $user_username . ' already exists'); } else { $user = new \App\Models\User(); $password = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20); $user->first_name = $first_name; $user->last_name = $last_name; $user->username = $user_username; $user->email = $user_email; $user->permissions = '{user":1}'; $user->password = bcrypt($password); $user->activated = 1; if ($user->save()) { $this->comment('User ' . $first_name . ' created'); } else { $this->error('ERROR CREATING User ' . $first_name . ' ' . $last_name); $this->error($user->getErrors()); } } } else { $user = new User(); } // Check for the location match and create it if it doesn't exist if ($location = Location::where('name', e($user_asset_location))->first()) { $this->comment('Location ' . $user_asset_location . ' already exists'); } else { $location = new Location(); if ($user_asset_location != '') { $location->name = e($user_asset_location); $location->address = ''; $location->city = ''; $location->state = ''; $location->country = ''; $location->user_id = 1; if (!$this->option('testrun') == 'true') { if ($location->save()) { $this->comment('Location ' . $user_asset_location . ' was created'); } else { $this->error('Something went wrong! Location ' . $user_asset_location . ' was NOT created'); $this->error($location->getErrors()); } } else { $this->comment('Location ' . $user_asset_location . ' was (not) created - test run only'); } } else { $this->comment('No location given, so none created.'); } } if (e($user_asset_category) == '') { $category_name = 'Unnamed Category'; } else { $category_name = e($user_asset_category); } // Check for the category match and create it if it doesn't exist if ($category = Category::where('name', e($category_name))->where('category_type', 'asset')->first()) { $this->comment('Category ' . $category_name . ' already exists'); } else { $category = new Category(); $category->name = e($category_name); $category->category_type = 'asset'; $category->user_id = 1; if ($category->save()) { $this->comment('Category ' . $user_asset_category . ' was created'); } else { $this->error('Something went wrong! Category ' . $user_asset_category . ' was NOT created'); $this->error($category->getErrors()); } } // Check for the manufacturer match and create it if it doesn't exist if ($manufacturer = Manufacturer::where('name', e($user_asset_mfgr))->first()) { $this->comment('Manufacturer ' . $user_asset_mfgr . ' already exists'); } else { $manufacturer = new Manufacturer(); $manufacturer->name = e($user_asset_mfgr); $manufacturer->user_id = 1; if ($manufacturer->save()) { $this->comment('Manufacturer ' . $user_asset_mfgr . ' was created'); } else { $this->error('Something went wrong! Manufacturer ' . $user_asset_mfgr . ' was NOT created: ' . $manufacturer->getErrors()->first()); } } // Check for the asset model match and create it if it doesn't exist if ($asset_model = AssetModel::where('name', e($user_asset_name))->where('modelno', e($user_asset_modelno))->where('category_id', $category->id)->where('manufacturer_id', $manufacturer->id)->first()) { $this->comment('The Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' already exists'); } else { $asset_model = new AssetModel(); $asset_model->name = e($user_asset_name); $asset_model->manufacturer_id = $manufacturer->id; $asset_model->modelno = e($user_asset_modelno); $asset_model->category_id = $category->id; $asset_model->user_id = 1; if ($asset_model->save()) { $this->comment('Asset Model ' . $user_asset_name . ' with model number ' . $user_asset_modelno . ' was created'); } else { $this->error('Something went wrong! Asset Model ' . $user_asset_name . ' was NOT created: ' . $asset_model->getErrors()->first()); } } // Check for the asset company match and create it if it doesn't exist if ($user_asset_company_name != '') { if ($company = Company::where('name', e($user_asset_company_name))->first()) { $this->comment('Company ' . $user_asset_company_name . ' already exists'); } else { $company = new Company(); $company->name = e($user_asset_company_name); if ($company->save()) { $this->comment('Company ' . $user_asset_company_name . ' was created'); } else { $this->error('Something went wrong! Company ' . $user_asset_company_name . ' was NOT created: ' . $company->getErrors()->first()); } } } else { $company = new Company(); } // Check for the asset match and create it if it doesn't exist if ($asset = Asset::where('asset_tag', e($user_asset_tag))->first()) { $this->comment('The Asset with asset tag ' . $user_asset_tag . ' already exists'); } else { $asset = new Asset(); $asset->name = e($user_asset_asset_name); if ($user_asset_purchase_date != '') { $asset->purchase_date = $user_asset_purchase_date; } else { $asset->purchase_date = null; } if ($user_asset_purchase_cost != '') { $asset->purchase_cost = ParseFloat(e($user_asset_purchase_cost)); } else { $asset->purchase_cost = 0.0; } $asset->serial = e($user_asset_serial); $asset->asset_tag = e($user_asset_tag); $asset->model_id = $asset_model->id; $asset->assigned_to = $user->id; $asset->rtd_location_id = $location->id; $asset->user_id = 1; $asset->status_id = $status_id; $asset->company_id = $company->id; if ($user_asset_purchase_date != '') { $asset->purchase_date = $user_asset_purchase_date; } else { $asset->purchase_date = null; } $asset->notes = e($user_asset_notes); if ($asset->save()) { $this->comment('Asset ' . $user_asset_name . ' with serial number ' . $user_asset_serial . ' was created'); } else { $this->error('Something went wrong! Asset ' . $user_asset_name . ' was NOT created: ' . $asset->getErrors()->first()); } } $this->comment('====================================='); return true; }); }
public function getEmployeeCompanyRegister(Request $request) { $addEmployee = new Employee(); $addEmployee->fullname = $request->input('fullname'); $addEmployee->username = $request->input('username'); $addEmployee->password = $request->input('password'); $addEmployee->email = $request->input('email'); $addEmployee->attribute = $request->input('attribute'); if ($addEmployee->save()) { $result = array("result" => "success"); } else { $result = array("result" => "failed"); } $username = \Input::get('username'); $password = \Input::get('password'); $query = DB::table('Employee')->where('username', $username)->where('password', $password)->select('employeeId')->first(); $addCompany = new Company(); $addCompany->companyName = $request->input('companyName'); $addCompany->generalAttributes = $request->input('generalAttributes'); $addCompany->purposeAndTopic = $request->input('purposeAndTopic'); $addCompany->companyCenterAndDepartment = $request->input('companyCenterAndDepartment'); $addCompany->jobDescription = $request->input('jobDescription'); $addCompany->companyAdress = $request->input('companyAdress'); $addCompany->employeeCount = $request->input('employeeCount'); $addCompany->companyMail = $request->input('companyMail'); $addCompany->employeeId = $query->employeeId; if ($addCompany->save()) { $result = array("result" => "success"); } else { $result = array("result" => "failed"); } return \View::make('ajaxResult', $result); }