/**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(RolesRequest $request)
 {
     $role = UserRole::where('id', $request['roleID'])->first();
     $role->name = $request['name'];
     $role->updated_by = \Auth::user()->id;
     $role->save();
     \Session::flash('success', 'well done! Role ' . $request['name'] . ' has been successfully updated!');
     return redirect()->back();
 }
 /**
  *	
  *	Description: Check and Save Account and Investors
  * 	Component: CreateInvestorAccount
  *
  */
 public function addAccount(ValidateAddInvestorPostRequest $request)
 {
     try {
         //Create user
         $isUsernameExist = true;
         $username = '';
         while ($isUsernameExist) {
             $username = '******' . (string) Uuid::uuid4();
             if (!User::where('userName', $username)->first()) {
                 $isUsernameExist = false;
             }
         }
         $user = User::create(['username' => $username]);
         $user->user_role_id = UserRole::where('name', 'Investor')->first()->id;
         $user->save();
     } catch (\Exception $e) {
         $user->delete();
         throw $e;
     }
     try {
         // Create Account
         $account = Account::create(['name' => $request->input('accountName'), 'type' => $request->input('accountType')]);
         $account->user_id = $user->id;
         $account->save();
     } catch (\Exception $e) {
         $user->delete();
         $account->delete();
         throw $e;
     }
     try {
         // Add Investor
         $investor = Investor::create(['firstName' => $request->input('firstName'), 'middleName' => $request->input('middleName') === '' ? null : $request->input('middleName'), 'lastName' => $request->input('lastName'), 'email' => $request->input('email') === '' ? null : $request->input('email')]);
         $investor->isOwner = true;
         $investor->account_id = $account->id;
         $investor->save();
     } catch (\Exception $e) {
         $user->delete();
         $account->delete();
         throw $e;
     }
     try {
         // Add Co Investors if Account Type = 'joint'
         if ($request->input('accountType') === 'joint') {
             foreach ($request->input('coInvestors') as $index => $value) {
                 $coInvestor = Investor::create(['firstName' => $value['coFirstName'], 'middleName' => $value['coMiddleName'] === '' ? null : $value['coMiddleName'], 'lastName' => $value['coLastName']]);
                 $coInvestor->account_id = $account->id;
                 $coInvestor->save();
             }
         }
     } catch (\Exception $e) {
         $investor = Investor::where('account_id', $account->id)->delete();
         $user->delete();
         $account->delete();
         throw $e;
     }
     return response()->json(['status' => 'success', 'message' => 'New Account Created.']);
 }
Exemple #3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $roleId = \App\UserRole::where('role', '=', 'Admin')->pluck('id');
     // echo $roleId;
     // $user = \App\User::firstOrCreate(['email' => '*****@*****.**']);
     // $user->name = 'Jill';
     // $user->email = '*****@*****.**';
     // $user->password = \Hash::make('helloworld');
     // $user->role_id = $roleId;
     // $user->save();
     //
     // $user = \App\User::firstOrCreate(['email' => '*****@*****.**']);
     // $user->name = 'Jamal';
     // $user->email = '*****@*****.**';
     // $user->password = \Hash::make('helloworld');
     // $user->role_id = $roleId;
     // $user->save();
     DB::table('users')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'user_role_id' => $roleId, 'name' => 'Jill', 'email' => '*****@*****.**', 'password' => \Hash::make('helloworld')]);
     DB::table('users')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'user_role_id' => $roleId, 'name' => 'Jamal', 'email' => '*****@*****.**', 'password' => \Hash::make('helloworld')]);
 }
 public function getAdminRoleOptions()
 {
     $roles = UserRole::where('name', '<>', 'Investor')->get();
     return $roles;
 }
Exemple #5
0
 public function setOwner(User $user)
 {
     $user->forgetPermissions();
     $role = Role::getOwnerRoleForBoard($this);
     if (!$role->wasRecentlyCreated) {
         UserRole::where('role_id', $role->role_id)->delete();
     }
     $this->operated_by = $user->user_id;
     $this->save();
     return UserRole::create(['user_id' => $user->user_id, 'role_id' => $role->role_id]);
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     if (\Schema::hasTable('positions')) {
         $positions = Position::all();
         $selectPositions = array();
         $selectPositions[0] = "Select / All";
         foreach ($positions as $position) {
             $selectPositions[$position->slug] = $position->name;
         }
         \View::share('selectPositions', $selectPositions);
     }
     if (\Schema::hasTable('cases_priorities')) {
         $priorities = CasePriority::all();
         $selectPriorities = array();
         $selectPriorities[0] = "Select / All";
         foreach ($priorities as $priority) {
             $selectPriorities[$priority->slug] = $priority->name;
         }
         \View::share('selectPriorities', $selectPriorities);
     }
     if (\Schema::hasTable('titles')) {
         $titles = Title::all();
         $selectTitles = array();
         $selectTitles[0] = "Select / All";
         foreach ($titles as $title) {
             $selectTitles[$title->slug] = $title->name;
         }
         \View::share('selectTitles', $selectTitles);
     }
     if (\Schema::hasTable('languages')) {
         $languages = Language::all();
         $selectLanguages = array();
         $selectLanguages[0] = "Select / All";
         foreach ($languages as $language) {
             $selectLanguages[$language->slug] = $language->name;
         }
         \View::share('selectLanguages', $selectLanguages);
     }
     if (\Schema::hasTable('departments')) {
         $departments = Department::all();
         $selectDepartments = array();
         $selectDepartments[0] = "Select / All";
         foreach ($departments as $department) {
             $selectDepartments[$department->slug] = $department->name;
         }
         \View::share('selectDepartments', $selectDepartments);
     }
     if (\Schema::hasTable('users_roles')) {
         $roles = UserRole::all();
         $selectRoles = array();
         $selectRoles[0] = "Select / All";
         foreach ($roles as $role) {
             $selectRoles[$role->slug] = $role->name;
         }
         \View::share('selectRoles', $selectRoles);
     }
     if (\Schema::hasTable('provinces')) {
         $provinces = Province::all();
         $selectProvinces = array();
         $selectProvinces[0] = "Select / All";
         foreach ($provinces as $Province) {
             $selectProvinces[$Province->slug] = $Province->name;
         }
         \View::share('selectProvinces', $selectProvinces);
     }
     if (\Schema::hasTable('districts')) {
         $districts = District::all();
         $selectDistrict = array();
         $selectDistricts[0] = "Select / All";
         foreach ($districts as $district) {
             $selectDistricts[$district->slug] = $district->name;
         }
         \View::share('selectDistricts', $selectDistricts);
     }
     if (\Schema::hasTable('municipalities')) {
         $municipalities = Municipality::all();
         $selectMunicipalities = array();
         $selectMunicipalities[0] = "Select / All";
         foreach ($municipalities as $municipality) {
             $selectMunicipalities[$municipality->slug] = $municipality->name;
         }
         \View::share('selectMunicipalities', $selectMunicipalities);
     }
     if (\Schema::hasTable('wards')) {
         $wards = Ward::all();
         $selectWards = array();
         $selectWards[0] = "Select / All";
         foreach ($wards as $ward) {
             $selectWards[$ward->slug] = $ward->name;
         }
         \View::share('selectWards', $selectWards);
     }
     if (\Schema::hasTable('categories')) {
         $categories = Category::all();
         $selectCategories = array();
         $selectCategories[0] = "Select / All";
         foreach ($categories as $category) {
             $selectCategories[$category->slug] = $category->name;
         }
         \View::share('selectCategories', $selectCategories);
     }
     if (\Schema::hasTable('sub_categories')) {
         $subCategories = SubCategory::all();
         $selectSubCategories = array();
         $selectSubCategories[0] = "Select / All";
         foreach ($subCategories as $subCategory) {
             $selectSubCategories[$subCategory->slug] = $subCategory->name;
         }
         \View::share('selectSubCategories', $selectSubCategories);
     }
     if (\Schema::hasTable('sub_sub_categories')) {
         $subSubCategories = SubSubCategory::all();
         $selectSubSubCategories = array();
         $selectSubSubCategories[0] = "Select / All";
         foreach ($subSubCategories as $subSubCategory) {
             $selectSubSubCategories[$subSubCategory->slug] = $subSubCategory->name;
         }
         \View::share('selectSubSubCategories', $selectSubSubCategories);
     }
     if (\Schema::hasTable('relationships')) {
         $relationships = Relationship::all();
         $selectRelationships = array();
         $selectRelationships[0] = "Select / All";
         foreach ($relationships as $relationship) {
             $selectRelationships[$relationship->id] = $relationship->name;
         }
         \View::share('selectRelationships', $selectRelationships);
     }
     if (\Schema::hasTable('cases')) {
         $cases = \DB::table('cases')->join('users', 'cases.reporter', '=', 'users.id')->select(\DB::raw("\n                                                    IF(`cases`.`addressbook` = 1,(SELECT CONCAT(`first_name`, ' ', `surname`) FROM `addressbook` WHERE `addressbook`.`id`= `cases`.`reporter`), (SELECT CONCAT(users.`name`, ' ', users.`surname`) FROM `users` WHERE `users`.`id`= `cases`.`reporter`)) as reporterName\n\n                                                "))->get();
         $reporters = array();
         $reporters[0] = "Select / All";
         foreach ($cases as $case) {
             $reporters[$case->reporterName] = $case->reporterName;
         }
         \View::share('selectReporters', $reporters);
     }
     View()->composer('master', function ($view) {
         $view->with('addressBookNumber', addressbook::all());
         if (\Auth::check()) {
             $number = addressbook::where('user', '=', \Auth::user()->id)->get();
             $view->with('addressBookNumber', $number);
             $allUsers = User::where('id', '<>', \Auth::user()->id)->get();
             $view->with('loggedInUsers', $allUsers);
             $noPrivateMessages = Message::where('to', '=', \Auth::user()->id)->where('read', '=', 0)->where('message_type', '=', 0)->get();
             $view->with('noPrivateMessages', $noPrivateMessages);
             $noInboxMessages = Message::where('to', '=', \Auth::user()->id)->where('message_type', '=', 0)->get();
             $view->with('noInboxMessages', $noInboxMessages);
             $noDepartments = Department::all();
             $view->with('noDepartments', $noDepartments);
             $noUsers = User::all();
             $view->with('noUsers', $noUsers);
             $noRoles = UserRole::all();
             $view->with('noRoles', $noRoles);
             $noPositions = Position::all();
             $view->with('noPositions', $noPositions);
             $noRelationships = Relationship::all();
             $view->with('noRelationships', $noRelationships);
             $noProvinces = Province::all();
             $view->with('noProvinces', $noProvinces);
             $noCaseStatuses = CaseStatus::all();
             $view->with('noCaseStatuses', $noCaseStatuses);
             $userRole = UserRole::where('id', '=', \Auth::user()->role)->first();
             $view->with('systemRole', $userRole);
             $noCasesPriorities = CasePriority::all();
             $view->with('noCasesPriorities', $noCasesPriorities);
         }
     });
 }
Exemple #7
0
/**
 * @return string
 */
function getAuthRole($user)
{
    $authUserId = $user->id;
    return \App\UserRole::where('user_id', $authUserId)->first()->role_id;
}
Exemple #8
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'user_role_id' => \App\UserRole::where('role', '=', 'Customer')->pluck('id')]);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function captureCaseUpdate(CaseRequest $request)
 {
     $houseHolderId = $request['hseHolderId'];
     $userRole = UserRole::where('name', '=', 'House Holder')->first();
     if ($houseHolderId < 1) {
         $user = new User();
         $user->role = $userRole->id;
         $user->name = $request['name'];
         $user->surname = $request['surname'];
         $user->cellphone = $request['cellphone'];
         $user->id_number = $request['id_number'];
         $user->position = $request['position'];
         $user->title = $request['title'];
         $user->house_number = $request['house_number'];
         $user->email = $request['cellphone'] . "@siyaleader.net";
         $user->created_by = \Auth::user()->id;
         $language = Language::where('slug', '=', $request['language'])->first();
         $user->language = $language->id;
         $province = Province::where('slug', '=', $request['province'])->first();
         $user->province = $province->id;
         $district = District::where('slug', '=', $request['district'])->first();
         $user->district = $district->id;
         $municipality = Municipality::where('slug', '=', $request['municipality'])->first();
         $user->municipality = $municipality->id;
         $ward = Ward::where('slug', '=', $request['ward'])->first();
         $user->ward = $ward->id;
         $user->save();
     }
     $casePriority = CasePriority::where('slug', '=', $request['priority'])->first();
     $case = CaseReport::find($request['caseID']);
     $case->description = $request['description'];
     $case->priority = $casePriority->id;
     $case->updated_by = \Auth::user()->id;
     $case->updated_at = \Carbon\Carbon::now('Africa/Johannesburg')->toDateTimeString();
     $case->save();
     return 'ok';
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(UpdateUserRequest $request)
 {
     $user = User::where('id', $request['userID'])->first();
     $role = UserRole::where('slug', '=', $request['role'])->first();
     $user->role = $role->id;
     $title = Title::where('slug', '=', $request['title'])->first();
     $user->title = $title->id;
     $user->name = $request['name'];
     $user->surname = $request['area'];
     $user->id_number = $request['id_number'];
     $user->alt_cellphone = $request['alt_cellphone'];
     $user->alt_email = $request['alt_email'];
     $province = Province::where('slug', '=', $request['province'])->first();
     $user->province = $province->id;
     $district = District::where('slug', '=', $request['district'])->first();
     $user->district = $district->id;
     $municipality = Municipality::where('slug', '=', $request['municipality'])->first();
     $user->municipality = $municipality->id;
     $ward = Ward::where('slug', '=', $request['ward'])->first();
     $user->ward = $ward->id;
     $user->area = $request['area'];
     $user->updated_by = \Auth::user()->id;
     $user->updated_at = \Carbon\Carbon::now('Africa/Johannesburg')->toDateTimeString();
     $user->save();
     \Session::flash('success', 'well done! User ' . $request['name'] . ' has been successfully updated!');
     return redirect()->back();
 }