Esempio n. 1
0
    protected function portalCreateEmployee() {
        
        $fName = Input::get('firstName');
        $lName = Input::get('lastName');
        $email = Input::get('email');
        $phone = Input::get('phone');
        $streetAddress = Input::get('streetAddress');
        $city = Input::get('city');
        $state = Input::get('state');
        $zipcode = Input::get('zipcode');
        $ssn = Input::get('ssn');
        $rate = Input::get('hourlyRate');
        $store = Input::get('primaryStoreId');
        $userType = Input::get('userTypeId');
        $username = Input::get('username');
        $password = Input::get('password');
        
        $newUser = User::create([
            'username'      => $username,
            'password'      => bcrypt($password),
            'created_at'    => gmdate('Y-m-d H:i:s'),
            'updated_at'    => gmdate('Y-m-d H:i:s'),
            'userTypeId'    => $userType
        ]);

        $userTypeId = $newUser->userTypeId;

        if ( $userTypeId == 1 || $userTypeId == 2) {

            $newEmployee = Employee::create([ 
                'userId'        => $newUser->id,
                'firstName'     => $fName,
                'lastName'      => $lName,
                'email'         => $email,
                'phone'         => $phone,
                'streetAddress' => $streetAddress,
                'city'          => $city,
                'state'         => $state,
                'zipcode'       => $zipcode,
                'ssn'           => $ssn,
                'hourlyRate'    => $rate,
                'primaryStoreId' => $store,
                'created_at'    => gmdate('Y-m-d H:i:s'),
            ]);

            $newTimesheet = Timesheet::create([
                'empId'    => $newEmployee->id,
                'sunday'    => 0,
                'monday'    => 0,
                'tuesday'   => 0,
                'wednesday' => 0,
                'thursday'  => 0,
                'friday'    => 0,
                'saturday'  => 0,
                'total'     => 0,
                'created_at'    => gmdate('Y-m-d H:i:s'),
            ]);

        }

        return Redirect::to('/portal-employees');
        
    }
Esempio n. 2
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     $newUser = User::create([
         'username'      => $data['username'],
         'password'      => bcrypt($data['password']),
         'created_at'    => gmdate('Y-m-d H:i:s'),
         'updated_at'    => gmdate('Y-m-d H:i:s'),
         'userTypeId'    => $data['userTypeId']
     ]);
     
     $userTypeId = $newUser->userTypeId;
     
     if ( $userTypeId == 1 || $userTypeId == 2) {
         
         $newEmployee = Employee::create([ 
             'userId'        => $newUser->id,
             'firstName'     => $data['firstName'],
             'lastName'      => $data['lastName'],
             'email'         => $data['email'],
             'phone'         => $data['phone'],
             'streetAddress' => $data['streetAddress'],
             'city'          => $data['city'],
             'state'         => $data['state'],
             'zipcode'       => $data['zipcode'],
             'ssn'           => $data['ssn'],
             'hourlyRate'    => $data['hourlyRate'],
             'primaryStoreId' => $data['primaryStoreId'],
             'created_at'    => gmdate('Y-m-d H:i:s'),
         ]);
         
         $newTimesheet = Timesheet::create([
             'userId'    => $newUser->id,
             'sunday'    => 0,
             'monday'    => 0,
             'tuesday'   => 0,
             'wednesday' => 0,
             'thursday'  => 0,
             'friday'    => 0,
             'saturday'  => 0,
             'total'     => 0,
             'created_at'    => gmdate('Y-m-d H:i:s'),
         ]);
         
     }
     
     if ( $userTypeId == 3 ) {
         
         if( array_key_exists('accountId', $data) ) {
             
             $newContact = Contact::create([
                 'userId'        => $newUser->id,
                 'accountId'     => $data['accountId'],
                 'firstName'     => $data['firstName'],
                 'lastName'      => $data['lastName'],
                 'email'         => $data['email'],
                 'phone'         => $data['phone'],
                 'contactTypeId' => $data['contactTypeId']
             ]);
             
         } else {
             
             $newAccount = Account::create([
                 'companyName'   => $data['companyName'],
                 'streetAddress' => $data['streetAddress'],
                 'city'          => $data['city'],
                 'state'         => $data['state'],
                 'zipcode'       => $data['zipcode'],
                 'accountStatus' => $data['accountStatus'],
             ]);
             
             $accntId = $newAccount->id;
             
             $newContant = Contact::create([
                 'empId'    => $newEmployee->id,
                 'accountId'     => $accntId,
                 'firstName'     => $data['firstName'],
                 'lastName'      => $data['lastName'],
                 'email'         => $data['email'],
                 'phone'         => $data['phone'],
                 'contactTypeId' => $data['contactTypeId']
             ]);
             
             $newBalance = Balance::create([
                 'accountId' => $accntId,
                 'balance' => 0.00
             ]);
             
         }
         
     }
     
     return $newUser;
 }