public function run()
 {
     $faker = Faker\Factory::create();
     for ($id = 1; $id < 19; $id++) {
         ContactInfo::create(['user_id' => $id, 'homenum' => $faker->randomElement(['6469330', '5320695', '1234567']), 'officenum' => $faker->randomElement(['8256325', '4598753', '3696542']), 'mobilenum' => '09064029842', 'street' => $faker->streetAddress, 'city' => $faker->randomElement(['Mandaluyong', 'Pasig'])]);
     }
 }
 public function run()
 {
     Eloquent::unguard();
     $faker = Faker::create();
     foreach (range(1, 5) as $index) {
         $contactNumber = new ContactNumber(['type' => $faker->numberBetween(1, 3), 'number' => $faker->phoneNumber]);
         $contactInfo = ContactInfo::create(['address_1' => $faker->streetAddress, 'address_2' => $faker->streetName, 'zip' => $faker->postcode, 'email' => $faker->email]);
         $contactInfo->contactNumbers()->save($contactNumber);
         $customer = Customer::create(['name' => $faker->company, 'industry_type' => $faker->numberBetween(1, 3), 'secretary_id' => $faker->numberBetween(5, 7)]);
         $customer->contactInfo()->save($contactInfo);
         $representative = CustomerRepresentative::create(['first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'middle_initial' => strtoupper($faker->randomLetter), 'company_position' => 'CEO']);
         $contactInfo = ContactInfo::create(['email' => $faker->email]);
         $contactNumber = new ContactNumber(['type' => $faker->numberBetween(1, 3), 'number' => $faker->phoneNumber]);
         $contactInfo->contactNumbers()->save($contactNumber);
         $representative->contactInfo()->save($contactInfo);
         $customer->representatives()->save($representative);
     }
 }
 /**
  * Store a newly created user in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), User::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $role = array_pull($data, 'role');
     $contact = array_pull($data, 'contactInfo');
     $numbers = array_pull($contact, 'number');
     $numberTypes = array_pull($contact, 'number_type');
     $data['password'] = Hash::make($data['password']);
     $user = User::create($data);
     foreach ($numbers as $index => $number) {
         $contactNumbers[] = new ContactNumber(['number' => $number, 'type' => $numberTypes[$index]]);
     }
     $contactInfo = ContactInfo::create($contact);
     $contactInfo->contactNumbers()->saveMany($contactNumbers);
     // Attach Address
     $user->contactInfo()->save($contactInfo);
     // Attach role
     $user->roles()->sync([$role]);
     return Redirect::route('users.index')->with('message', 'Successfully added user')->with('alert-class', 'success');
 }
 public function postRegister()
 {
     $validator = Validator::make(Input::all(), User::$rules);
     if ($validator->fails()) {
         return Redirect::route('register')->withErrors($validator)->withInput();
     }
     $user = User::create(['firstname' => Input::get('firstname'), 'middlename' => Input::get('middlename'), 'lastname' => Input::get('lastname'), 'email' => Input::get('email'), 'username' => Input::get('username'), 'password' => Hash::make(Input::get('password')), 'department_id' => Input::get('department_id'), 'birthday' => Input::get('birthday'), 'birthplace' => Input::get('birthplace'), 'gender' => Input::get('gender'), 'civilstatus' => Input::get('civilstatus'), 'citizenship' => Input::get('citizenship'), 'height' => Input::get('height'), 'weight' => Input::get('weight'), 'bloodtype' => Input::get('bloodtype'), 'datehired' => Input::get('datehired'), 'pos_id' => Input::get('pos_id'), 'status' => Input::get('status')]);
     // $user->department()->attach(Input::get('department_id'));
     $lastid = User::orderBy('id', 'desc')->first();
     $contacts = ContactInfo::create(['user_id' => $lastid->id, 'homenum' => Input::get('homenum'), 'officenum' => Input::get('officenum'), 'mobilenum' => Input::get('mobilenum'), 'street' => Input::get('street'), 'city' => Input::get('city')]);
     $commonid = CommonId::create(['user_id' => $lastid->id, 'tin' => input::get('taxid'), 'philhealth' => input::get('philhealth'), 'pagibig' => input::get('pagibig'), 'sss' => input::get('sss'), 'gsisbp' => input::get('gsisbp'), 'gsispolicy' => input::get('gsispol'), 'gsisoptional' => input::get('gsisopt'), 'educplan' => input::get('educplan')]);
     $father = Parents::create(['user_id' => $lastid->id, 'parent_id' => Input::get('fatherid'), 'firstname' => Input::get('fatherfirstname'), 'middlename' => Input::get('fathermiddlename'), 'lastname' => Input::get('fatherlastname'), 'address' => Input::get('fatheraddress')]);
     $mother = Parents::create(['user_id' => $lastid->id, 'parent_id' => Input::get('motherid'), 'firstname' => Input::get('motherfirstname'), 'middlename' => Input::get('mothermiddlename'), 'lastname' => Input::get('motherlastname'), 'address' => Input::get('motheraddress')]);
     $vacleave = LeaveBalance::create(['user_id' => $lastid->id, 'balance' => 1.25, 'leavetype_id' => 1]);
     $sickleave = LeaveBalance::create(['user_id' => $lastid->id, 'balance' => 1.25, 'leavetype_id' => 2]);
     $patleave = LeaveBalance::create(['user_id' => $lastid->id, 'leavetype_id' => 3]);
     $patleave = LeaveBalance::create(['user_id' => $lastid->id, 'leavetype_id' => 4]);
     $birthleave = LeaveBalance::create(['user_id' => $lastid->id, 'leavetype_id' => 5]);
     $school = School::create(['user_id' => $lastid->id]);
     $evalpoints = EvaluatePoints::create(['user_id' => $lastid->id]);
     $audit = AuditTrail::create(['user_id' => Auth::id(), 'role' => 'Employee Management Admin', 'action' => 'registered a new EMPLOYEE "' . $lastid->firstname . ' ' . $lastid->lastname . '".']);
     return Redirect::route('register')->with('alert', 'success|' . $user->formatName(':fn :mi :ln') . ' has been registered successfully.');
 }
 public function storeRepresentative($id)
 {
     $input = Input::all();
     $rules = ['first_name' => 'required', 'last_name' => 'required', 'company_position' => 'required', 'contactInfo.email' => 'required|email'];
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $contact = array_pull($input, 'contactInfo');
     $numbers = array_pull($contact, 'number');
     $numberTypes = array_pull($contact, 'number_type');
     $representative = CustomerRepresentative::create($input);
     $customer = Customer::find($id);
     foreach ($numbers as $index => $number) {
         $contactNumbers[] = new ContactNumber(['number' => $number, 'type' => $numberTypes[$index]]);
     }
     $newContactInfo = ContactInfo::create($contact);
     $newContactInfo->contactNumbers()->saveMany($contactNumbers);
     $representative->contactInfo()->save($newContactInfo);
     $customer->representatives()->save($representative);
     if (Session::get('redirect_to_rfq_after_create')) {
         Session::pull('redirect_to_rfq_after_create');
         return Redirect::route('quotations.create', ['customerId' => $customer->id]);
     }
     if (Session::get('redirect_to_rfq')) {
         $url = Session::pull('redirect_to_rfq');
         return Redirect::to($url)->with('message', 'Successfully added representative')->with('alert-class', 'success');
     }
     return Redirect::route('customers.edit', ['id' => $id])->with('message', 'Successfully added representative')->with('alert-class', 'success');
 }
 public function run()
 {
     $faker = Faker::create();
     // Get roles
     $admin = Role::find(1);
     $secretary = Role::find(2);
     $technical = Role::find(3);
     $executive = Role::find(4);
     $procurement = Role::find(5);
     $contactNumber = new ContactNumber(['type' => $faker->numberBetween(1, 3), 'number' => $faker->phoneNumber]);
     $contactInfo = ContactInfo::create(['address_1' => $faker->streetAddress, 'address_2' => $faker->streetName, 'zip' => $faker->postcode, 'email' => $faker->email]);
     $contactInfo->contactNumbers()->save($contactNumber);
     $gat = User::create(['username' => 'Gatix', 'email' => '*****@*****.**', 'password' => Hash::make('Sand1gan'), 'first_name' => 'Gat', 'last_name' => 'Manuel', 'company_name' => 'Gatix', 'company_position' => 'Dev']);
     $gat->attachRoles([$admin, $secretary, $technical, $executive, $procurement]);
     $gat->contactInfo()->save($contactInfo);
     // Admins
     foreach (range(1, 3) as $index) {
         $contactNumber = new ContactNumber(['type' => $faker->numberBetween(1, 3), 'number' => $faker->phoneNumber]);
         $contactInfo = ContactInfo::create(['address_1' => $faker->streetAddress, 'address_2' => $faker->streetName, 'zip' => $faker->postcode, 'email' => $faker->email]);
         $contactInfo->contactNumbers()->save($contactNumber);
         $user = User::create(['username' => 'admin_' . $index, 'email' => $faker->email, 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'middle_initial' => strtoupper($faker->randomLetter), 'company_name' => $faker->company, 'password' => Hash::make('password'), 'company_position' => 'Admin']);
         $user->attachRole($admin);
         $user->contactInfo()->save($contactInfo);
     }
     // Secretaries
     foreach (range(1, 3) as $index) {
         $contactNumber = new ContactNumber(['type' => $faker->numberBetween(1, 3), 'number' => $faker->phoneNumber]);
         $contactInfo = ContactInfo::create(['address_1' => $faker->streetAddress, 'address_2' => $faker->streetName, 'zip' => $faker->postcode, 'email' => $faker->email]);
         $contactInfo->contactNumbers()->save($contactNumber);
         $user = User::create(['username' => 'secretary_' . $index, 'email' => $faker->email, 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'middle_initial' => strtoupper($faker->randomLetter), 'company_name' => $faker->company, 'password' => Hash::make('password'), 'company_position' => 'Secretary']);
         $user->attachRole($secretary);
         $user->contactInfo()->save($contactInfo);
     }
     // Technicals
     foreach (range(1, 3) as $index) {
         $contactNumber = new ContactNumber(['type' => $faker->numberBetween(1, 3), 'number' => $faker->phoneNumber]);
         $contactInfo = ContactInfo::create(['address_1' => $faker->streetAddress, 'address_2' => $faker->streetName, 'zip' => $faker->postcode, 'email' => $faker->email]);
         $contactInfo->contactNumbers()->save($contactNumber);
         $user = User::create(['username' => 'technical_' . $index, 'email' => $faker->email, 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'middle_initial' => strtoupper($faker->randomLetter), 'company_name' => $faker->company, 'password' => Hash::make('password'), 'company_position' => 'Technical Reviewer']);
         $user->attachRole($technical);
         $user->contactInfo()->save($contactInfo);
     }
     // Executives
     foreach (range(1, 3) as $index) {
         $contactNumber = new ContactNumber(['type' => $faker->numberBetween(1, 3), 'number' => $faker->phoneNumber]);
         $contactInfo = ContactInfo::create(['address_1' => $faker->streetAddress, 'address_2' => $faker->streetName, 'zip' => $faker->postcode, 'email' => $faker->email]);
         $contactInfo->contactNumbers()->save($contactNumber);
         $user = User::create(['username' => 'executive_' . $index, 'email' => $faker->email, 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'middle_initial' => strtoupper($faker->randomLetter), 'company_name' => $faker->company, 'password' => Hash::make('password'), 'company_position' => 'Executive']);
         $user->attachRole($executive);
         $user->contactInfo()->save($contactInfo);
     }
     // Procurement
     foreach (range(1, 3) as $index) {
         $contactNumber = new ContactNumber(['type' => $faker->numberBetween(1, 3), 'number' => $faker->phoneNumber]);
         $contactInfo = ContactInfo::create(['address_1' => $faker->streetAddress, 'address_2' => $faker->streetName, 'zip' => $faker->postcode, 'email' => $faker->email]);
         $contactInfo->contactNumbers()->save($contactNumber);
         $user = User::create(['username' => 'procurement_' . $index, 'email' => $faker->email, 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'middle_initial' => strtoupper($faker->randomLetter), 'company_name' => $faker->company, 'password' => Hash::make('password'), 'company_position' => 'Procurement']);
         $user->attachRole($procurement);
         $user->contactInfo()->save($contactInfo);
     }
 }