Ejemplo n.º 1
0
 public function update($id, UpdatePersonRequest $request)
 {
     $person = Person::find($id);
     if (Input::file('profile_picture') && Input::file('profile_picture')->isValid()) {
         $request['file'] = Input::file('profile_picture');
         $request['target'] = "people";
         $request['target_id'] = $person->id;
         $request['uploader_id'] = Auth::user()->active_contact->id;
         $repo = new FilesRepository();
         $result = $repo->upload($request);
         if (!$result['error']) {
             $old_profile_picture = $person->profile_picture_id;
             if (!is_null($old_profile_picture)) {
                 $person->profile_picture_id = NULL;
                 $person->save();
                 $repo->destroy($old_profile_picture);
             }
             $person->profile_picture_id = $result['id'];
             $person->save();
         }
     }
     $person->update($request->all());
     return redirect()->route('people.show', $id)->with('successes', ['person updated successfully']);
 }
Ejemplo n.º 2
0
 public function storeInfo(StartRequest $request)
 {
     if (Session::get("start_session")) {
         $user = User::find(Session::get("start_session.user_id"));
         $person = $user->owner;
         if (Input::file('profile_picture') && Input::file('profile_picture')->isValid()) {
             $request['file'] = Input::file('profile_picture');
             $request['target'] = "people";
             $request['target_id'] = $person->id;
             $request['uploader_id'] = $user->active_contact->id;
             $repo = new FilesRepository();
             $result = $repo->upload($request);
             if (!$result['error']) {
                 $old_profile_picture = $person->profile_picture_id;
                 if (!is_null($old_profile_picture)) {
                     $person->profile_picture_id = NULL;
                     $person->save();
                     $repo->destroy($old_profile_picture);
                 }
                 $person->profile_picture_id = $result['id'];
                 $person->save();
             }
         }
         if (Session::get("start_session.safe_enough") == false) {
             $user->password = Hash::make($request->get('password'));
         }
         $user->last_login = Carbon::now();
         $user->save();
         $person->first_name = $request->get('first_name');
         $person->last_name = $request->get('last_name');
         $person->save();
         if ($request->get('use_info_all_contacts') == "true") {
             $new_contact = $request->get('contact');
             foreach ($person->company_person as $contact) {
                 $contact->phone = $new_contact['phone'];
                 $contact->extension = $new_contact['extension'];
                 $contact->cellphone = $new_contact['cellphone'];
                 $contact->email = $new_contact['email'];
                 $contact->department_id = $new_contact['department_id'];
                 $contact->title_id = $new_contact['title_id'];
                 $contact->save();
             }
         } else {
             $contacts = $request->get('contacts');
             foreach ($contacts as $key => $new_contact) {
                 $contact = CompanyPerson::find($key);
                 $contact->phone = $new_contact['phone'];
                 $contact->extension = $new_contact['extension'];
                 $contact->cellphone = $new_contact['cellphone'];
                 $contact->email = $new_contact['email'];
                 $contact->department_id = $new_contact['department_id'];
                 $contact->title_id = $new_contact['title_id'];
                 $contact->save();
             }
         }
         Session::flush();
     }
     return redirect()->route('login.login')->withErrors(['Please, login again']);
 }
 public function update($id, UpdateCompanyRequest $request)
 {
     $company = Company::find($id);
     if (Input::file('profile_picture') && Input::file('profile_picture')->isValid()) {
         $request['file'] = Input::file('profile_picture');
         $request['target'] = "companies";
         $request['target_id'] = $company->id;
         $request['uploader_id'] = Auth::user()->active_contact->id;
         $repo = new FilesRepository();
         $result = $repo->upload($request);
         if (!$result['error']) {
             $old_profile_picture = $company->profile_picture_id;
             if (!is_null($old_profile_picture)) {
                 $company->profile_picture_id = NULL;
                 $company->save();
                 $repo->destroy($old_profile_picture);
             }
             $company->profile_picture_id = $result['id'];
             $company->save();
         }
     }
     $company->update($request->all());
     $company_account_manager = CompanyAccountManager::where('company_id', '=', $id)->first();
     // update account manager
     if (isset($company_account_manager)) {
         $company_account_manager->account_manager_id = Input::get('account_manager_id');
         $company_account_manager->save();
     } else {
         $company_account_manager = new CompanyAccountManager();
         $company_account_manager->company_id = $id;
         $company_account_manager->account_manager_id = Input::get('account_manager_id');
         $company_account_manager->save();
     }
     // update main contact
     $main_contact = CompanyMainContact::where('company_id', '=', $id)->first();
     if (isset($main_contact)) {
         $main_contact->main_contact_id = Input::get('main_contact_id');
         $main_contact->save();
     } else {
         $main_contact = new CompanyMainContact();
         $main_contact->company_id = $id;
         $main_contact->main_contact_id = Input::get('account_manager_id');
         $main_contact->save();
     }
     return redirect()->route('companies.show', $id)->with('successes', ['company updated successfully']);
 }