static function sign_up($params) { if (filter_var($params['email'], FILTER_VALIDATE_EMAIL)) { return User::insertGetId($params); } else { return ["status" => 0, "error" => "INV_EMAIL"]; } }
public function store() { // Transaction strats here because we are connecting three tables \DB::beginTransaction(); //User credintial information $username = \Input::get('branch_code'); $password = str_random(10); $p_email = \Input::get('p_email'); $s_contact_person = \Input::get('s_contact_person'); $hashPassword = \Hash::make($password); //Insert user credentials $uId = \User::insertGetId(array('username' => $username, 'password' => $hashPassword, 'email' => $p_email, 'profilesId' => 2, 'active' => 'Y', 'displayname' => $s_contact_person)); if (!$uId) { \DB::rollback(); return \Redirect::back()->with('error', 'Failed to save'); } $branch_name = \Input::get('branch_name'); $branch_code = \Input::get('branch_code'); $branch_address = \Input::get('branch_address'); $branch_city = \Input::get('branch_city'); $branch_state = \Input::get('branch_state'); $branch_pin = \Input::get('branch_pin'); $branch_land_line = \Input::get('branch_land_line'); $branch_alt_land_line = \Input::get('branch_alt_land_line'); $branch_fax = \Input::get('branch_fax'); // Insert Branch into table $branchId = \Branch::insertGetId(array('branch_name' => $branch_name, 'branch_code' => $branch_code, 'branch_address' => $branch_address, 'branch_city' => $branch_city, 'branch_state' => $branch_state, 'branch_pin' => $branch_pin, 'branch_land_line' => $branch_land_line, 'branch_alt_land_line' => $branch_alt_land_line, 'branch_fax' => $branch_fax, 'user_id' => $uId)); if (!$branchId) { \DB::callback(); return \Redirect::back()->with('error', 'Failed to save'); } // Branch contact information $branch_head = \Input::get('branch_head'); $p_mobile_no = \Input::get('p_mobile_no'); $p_alt_mobile_no = \Input::get('p_alt_mobile_no'); $p_email = \Input::get('p_email'); $p_alt_email = \Input::get('p_alt_email'); $s_mobile_no = \Input::get('s_mobile_no'); $s_alt_mobile_no = \Input::get('s_alt_mobile_no'); $s_email = \Input::get('s_email'); $s_alt_email = \Input::get('s_alt_email'); //Insert Data to contact table $contactId = \BranchContact::insertGetId(array('branch_head' => $branch_head, 'p_mobile_no' => $p_mobile_no, 'p_alt_mobile_no' => $p_alt_mobile_no, 'p_email' => $p_email, 'p_alt_email' => $p_alt_email, 's_contact_person' => $s_contact_person, 's_mobile_no' => $s_mobile_no, 's_alt_mobile_no' => $s_alt_mobile_no, 's_email' => $s_email, 's_alt_email' => $s_alt_email, 'user_id' => $uId, 'branch_id' => $branchId)); if (!$contactId) { \DB::rollback(); return \Redirect::back()->with('error', 'Failed to add'); } elseif ($contactId) { \DB::commit(); \Mail::send('emails.user_credential', array('name' => $s_contact_person, 'username' => $username, 'password' => $password), function ($message) use($p_email, $username) { $message->to($p_email, $username)->subject('User Credential'); }); return \Redirect::back()->with('success', 'Successfully added'); } print_r(\Input::all()); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $uId = \Auth::user()->id; // User details // Transaction begins here \DB::beginTransaction(); $displayname = \Input::get('displayname'); $email = \Input::get('email'); $username = \Input::get('company_code'); $password = str_random(10); $hashPassword = \Hash::make($password); $user = \User::insertGetId(array('displayname' => $displayname, 'email' => $email, 'username' => $username, 'password' => $hashPassword, 'profilesId' => 3, 'active' => 'Y')); if (!$user) { \DB::rollback(); return \Redirect::back()->with('error', 'Failed to add'); } // User contact $mobile = \Input::get('mobile'); $alt_mobile = \Input::get('alt_mobile'); $alt_email = \Input::get('alt_email'); //Insert data to user contact table $contact = \UserContact::insert(array('mobile' => $mobile, 'alt_mobile' => $alt_mobile, 'alt_email' => $alt_email)); // insert frends table $friends = \Friends::insert(array('child_id' => $user, 'parent_id' => $uId, 'profilesId' => 3)); if (!$friends) { \DB::rollback(); return \Redirect::back()->with('error', 'Failed to add'); } //Company info $company_name = \Input::get('company_name'); $company_address = \Input::get('company_address'); $company_city = \Input::get('company_city'); $company_state = \Input::get('company_state'); $company_pin = \Input::get('company_pin'); $company_land_line = \Input::get('company_land_line'); $company_alt_land_line = \Input::get('company_alt_land_line'); $company_fax = \Input::get('company_fax'); $company_website = \Input::get('company_website'); //Insert data to company table $company = \Company::insertGetId(array('company_name' => $company_name, 'company_address' => $company_address, 'company_city' => $company_city, 'company_state' => $company_state, 'company_pin' => $company_pin, 'company_phone' => $company_land_line, 'company_alt_phone' => $company_alt_land_line, 'company_fax' => $company_fax, 'company_website' => $company_website, 'user_id' => $user)); // if company not inserted the rollback if (!$company) { \DB::rollback(); return \Redirect::back()->with('error', 'Failed to add'); } elseif ($company) { \DB::commit(); \Mail::send('emails.user_credential', array('name' => $displayname, 'username' => $username, 'password' => $password), function ($message) use($email, $username) { $message->to($email, $username)->subject('User Credential'); }); return \Redirect::route('branch.client.index')->with('success', 'Successfully added'); } }
public function postImportEmp() { if (\Request::ajax()) { $efile = \Input::file('upload'); /* Validation of file */ $validate = \Validator::make(array('file' => $efile), array('file' => 'required|mimes:xls,csv|max:2000|min:1')); if ($validate->fails()) { $error = array('error' => $validate->messages()->first()); echo json_encode($error); return; } else { $handle = file($efile->getRealPath()); /* Call Excel Class */ $objPHPExcel = \PHPExcel_IOFactory::load($efile->getRealPath()); $mainArr = array(); foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { // Sheet names switch ($worksheet->getTitle()) { case 'User': $index = 'users'; break; case 'PersonalDetails': $index = 'PersonalDetails'; break; case 'ContactInfo': $index = 'ContactInfo'; break; case 'IdentificationandBankInfo': $index = 'IdentificationandBankInfo'; break; case 'PFandESIInformation': $index = 'PFandESIInformation'; break; case 'JobDetails': $index = 'JobDetails'; break; case 'EducationalBackground': $index = 'EducationalBackground'; break; case 'WorkExperience': $index = 'WorkExperience'; break; } // Getting all cells $subArr = array(); $rows = $worksheet->getRowIterator(); foreach ($rows as $row) { $cells = $row->getCellIterator(); // cells store into data array $data = array(); foreach ($cells as $cell) { $data[] = $cell->getCalculatedValue(); } if ($data) { // one set of row stored in indexed array $arr[$index] = $data; // indexed array store into subarr $subArr[] = $arr; // remove indexd array for optimiced douplicated unset($arr); } } // every sheet of array store in main Arr $mainArr[$index] = $subArr; unset($subArr); } $emails = array_fetch($mainArr['users'], 'users.1'); // Validate emails foreach ($emails as $value) { if (preg_match("/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}\$/", $value)) { } else { $error = array('error' => "{$value} InValid Email"); echo json_encode($error); return; } } // validation email unique from excel if (count($emails) != count(array_unique($emails))) { $error = array('error' => "Douplicate emails are available"); echo json_encode($error); return; } //end email unique in excel //Check Email Id is unique or not $user = \User::withTrashed()->whereIn('email', $emails)->first(); if ($user) { $error = array('error' => "{$user->email} already registered"); echo json_encode($error); return; } // Database insertion starts here $users = $mainArr['users']; $PersonalDetails = $mainArr['PersonalDetails']; $ContactInfo = $mainArr['ContactInfo']; $IdentificationandBankInfo = $mainArr['IdentificationandBankInfo']; $PFandESIInformation = $mainArr['PFandESIInformation']; $JobDetails = $mainArr['JobDetails']; $EducationalBackground = $mainArr['EducationalBackground']; $WorkExperience = $mainArr['WorkExperience']; // Create UserId $userID = \Auth::user()->id; $branch = \Branch::where('user_id', '=', $userID)->first(); $prifix = $branch->branch_code; // branch prifix code $count = \BranchEmp::withTrashed()->where('branch_id', '=', $userID)->count(); // count all registered user of this branch $i = 0; foreach ($users as $val) { \DB::beginTransaction(); $temp = $count + 1; // increase one $count++; $postfix = sprintf('%04d', $temp); // manupulate 000$temp $username = $prifix . $postfix; $password = str_random(10); $hashPassword = \Hash::make($password); $email = $val['users'][1]; $uId = \User::insertGetId(array('username' => $username, 'password' => $hashPassword, 'displayname' => $val['users'][0], 'email' => $val['users'][1], 'profilesId' => 4, 'active' => 'Y')); //create branch employee $branchEmployee = \BranchEmp::insertGetId(array('branch_id' => $userID, 'emp_id' => $uId)); // Insert Personal detail $empId = \Employee::insertGetId(array('user_id' => $uId, 'firstname' => $PersonalDetails[$i]['PersonalDetails'][0], 'lastname' => $PersonalDetails[$i]['PersonalDetails'][2], 'middlename' => $PersonalDetails[$i]['PersonalDetails'][1], 'fathername' => $PersonalDetails[$i]['PersonalDetails'][3], 'mothermaiden' => $PersonalDetails[$i]['PersonalDetails'][8], 'dateofbirth' => $PersonalDetails[$i]['PersonalDetails'][4], 'maritialstatus' => $PersonalDetails[$i]['PersonalDetails'][5], 'spousename' => $PersonalDetails[$i]['PersonalDetails'][6], 'sibling' => $PersonalDetails[$i]['PersonalDetails'][8], 'bloodgroup' => $PersonalDetails[$i]['PersonalDetails'][9])); // Contact Information $contact = \UserContact::insertGetId(array('user_id' => $uId, 'address' => $ContactInfo[$i]['ContactInfo'][0], 'city' => $ContactInfo[$i]['ContactInfo'][1], 'state' => $ContactInfo[$i]['ContactInfo'][2], 'pin' => $ContactInfo[$i]['ContactInfo'][3], 'p_address' => $ContactInfo[$i]['ContactInfo'][4], 'p_city' => $ContactInfo[$i]['ContactInfo'][5], 'p_state' => $ContactInfo[$i]['ContactInfo'][6], 'p_pin' => $ContactInfo[$i]['ContactInfo'][7], 'mobile' => $ContactInfo[$i]['ContactInfo'][8], 'phone' => $ContactInfo[$i]['ContactInfo'][9], 'alt_mobile' => $ContactInfo[$i]['ContactInfo'][10], 'alt_email' => $ContactInfo[$i]['ContactInfo'][11])); //IdentificationandBankInfo $identification = \EmpIdentification::insertGetId(array('user_id' => $uId, 'pan' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][0], 'passport_no' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][1], 'adhar_no' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][2], 'voter_id' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][3], 'driving_licence' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][4])); // Bank Detail $bankDetails = \EmpBankDetail::insertGetId(array('user_id' => $uId, 'account_no' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][5], 'bank_name' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][6], 'branch' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][7], 'IFSC' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][8], 'micrno' => $IdentificationandBankInfo[$i]['IdentificationandBankInfo'][9])); // Esi and PF Detail $PfEsi = \PfEsi::insertGetId(array('user_id' => $uId, 'isPF' => $PFandESIInformation[$i]['PFandESIInformation'][0], 'pfno' => $PFandESIInformation[$i]['PFandESIInformation'][1], 'pfenno' => $PFandESIInformation[$i]['PFandESIInformation'][2], 'epfno' => $PFandESIInformation[$i]['PFandESIInformation'][3], 'relationship' => $PFandESIInformation[$i]['PFandESIInformation'][4], 'isESI' => $PFandESIInformation[$i]['PFandESIInformation'][5], 'esino' => $PFandESIInformation[$i]['PFandESIInformation'][6])); // Job details $jobdetailsId = \JobDetails::insertGetId(array('user_id' => $uId, 'joining_date' => $JobDetails[$i]['JobDetails'][0], 'job_type' => $JobDetails[$i]['JobDetails'][1], 'designation' => $JobDetails[$i]['JobDetails'][2], 'department' => $JobDetails[$i]['JobDetails'][3], 'reporting_manager' => $JobDetails[$i]['JobDetails'][4], 'payment_mode' => $JobDetails[$i]['JobDetails'][5], 'hr_verification' => $JobDetails[$i]['JobDetails'][6], 'police_verification' => $JobDetails[$i]['JobDetails'][7], 'emp_type' => $JobDetails[$i]['JobDetails'][8], 'client_id' => $JobDetails[$i]['JobDetails'][9])); //EducationalBackground $eduction = \EmpEducation::insertGetId(array('user_id' => $uId, 'school_name' => $EducationalBackground[$i]['EducationalBackground'][0], 'school_location' => $EducationalBackground[$i]['EducationalBackground'][1], 'school_percentage' => $EducationalBackground[$i]['EducationalBackground'][2], 'puc_name' => $EducationalBackground[$i]['EducationalBackground'][3], 'puc_location' => $EducationalBackground[$i]['EducationalBackground'][4], 'puc_percentage' => $EducationalBackground[$i]['EducationalBackground'][5], 'diploma_name' => $EducationalBackground[$i]['EducationalBackground'][6], 'diploma_location' => $EducationalBackground[$i]['EducationalBackground'][7], 'diploma_percentage' => $EducationalBackground[$i]['EducationalBackground'][8], 'degree_name' => $EducationalBackground[$i]['EducationalBackground'][9], 'degree_location' => $EducationalBackground[$i]['EducationalBackground'][10], 'degree_percentage' => $EducationalBackground[$i]['EducationalBackground'][11], 'master_name' => $EducationalBackground[$i]['EducationalBackground'][12], 'master_location' => $EducationalBackground[$i]['EducationalBackground'][13], 'master_percentage' => $EducationalBackground[$i]['EducationalBackground'][14])); // Experiance $companyDetails = \WorkExperiance::insertGetId(array('user_id' => $uId, 'company_name' => $WorkExperience[$i]['WorkExperience'][0], 'location' => $WorkExperience[$i]['WorkExperience'][1], 'designation' => $WorkExperience[$i]['WorkExperience'][2], 'last_ctc' => $WorkExperience[$i]['WorkExperience'][3], 'join_date' => $WorkExperience[$i]['WorkExperience'][4], 'leaving_date' => $WorkExperience[$i]['WorkExperience'][5])); \DB::commit(); \Mail::send('emails.user_credential', array('name' => $val['users'][0], 'username' => $username, 'password' => $password), function ($message) use($email, $username) { $message->to($email, $username)->subject('User Credential'); }); $i++; } // end foreach of database insertion // success message $success = array('success' => "Successfully uploaded your Employees"); echo json_encode($success); return; } // end else part } // end ajax condition }