public function getProfile($user_id)
 {
     $userProfile = UserProfile::where('id', '=', $user_id)->first();
     $userid = $userProfile->id;
     $userfname = $userProfile->fname;
     $userlname = $userProfile->lname;
     $userstreetno = $userProfile->streetno;
     $userstreet = $userProfile->street;
     $usersuburb = $userProfile->suburb;
     $userstate = $userProfile->state;
     $userpostcode = $userProfile->postcode;
     $userdobday = $userProfile->day_dob;
     $userdobmonth = $userProfile->month_dob;
     $userdobyear = $userProfile->year_dob;
     $userphone = $userProfile->phone;
     $usertfn = $userProfile->tfn;
     $userpidtype = $userProfile->pidtype;
     $userpidnum = $userProfile->pidnum;
     $usersidtype = $userProfile->sidtype;
     $usersidnum = $userProfile->sidnum;
     $userdes = $userProfile->description;
     $usergender = $userProfile->gender;
     $useroccupation = $userProfile->occupation;
     $data = array('userid' => $userid, 'userfname' => $userfname, 'userlname' => $userlname, 'userstreetno' => $userstreetno, 'userstreet' => $userstreet, 'usersuburb' => $usersuburb, 'userstate' => $userstate, 'userpostcode' => $userpostcode, 'day_dob' => $userdobday, 'month_dob' => $userdobmonth, 'year_dob' => $userdobyear, 'userphone' => $userphone, 'usertfn' => $usertfn, 'userpidtype' => $userpidtype, 'userpidnum' => $userpidnum, 'usersidtype' => $usersidtype, 'usersidnum' => $usersidnum, 'userdes' => $userdes, 'usergender' => $usergender, 'useroccupation' => $useroccupation);
     return $data;
 }
 public function editProfile()
 {
     $id = Auth::user()->id;
     $usermail = Auth::user()->email;
     $userProfile = UserProfile::where('id', '=', $id)->first();
     if ($userProfile == null) {
         // if user has not add it profile.
         return View::make('editprofiles')->with('usermail', $usermail);
     }
     $userfname = $userProfile->fname;
     $userlname = $userProfile->lname;
     $userstreetno = $userProfile->streetno;
     $userstreet = $userProfile->street;
     $usersuburb = $userProfile->suburb;
     $userstate = $userProfile->state;
     $userpostcode = $userProfile->postcode;
     $userdob = $userProfile->dob;
     $userphone = $userProfile->phone;
     $usertfn = $userProfile->tfn;
     $userpidtype = $userProfile->pidtype;
     $userpidnum = $userProfile->pidnum;
     $usersidtype = $userProfile->sidtype;
     $usersidnum = $userProfile->sidnum;
     $userdes = $userProfile->description;
     $data = array('usermail' => $usermail, 'userfname' => $userfname, 'userlname' => $userlname, 'userstreetno' => $userstreetno, 'userstreet' => $userstreet, 'usersuburb' => $usersuburb, 'userstate' => $userstate, 'userpostcode' => $userpostcode, 'userdob' => $userdob, 'userphone' => $userphone, 'usertfn' => $usertfn, 'userpidtype' => $userpidtype, 'userpidnum' => $userpidnum, 'usersidtype' => $usersidtype, 'usersidnum' => $usersidnum, 'userdes' => $userdes, 'usergender' => $userProfile->gender, 'useroccuptaion' => $userProfile->occupation);
     return View::make('editprofiles', array('data' => $data));
 }
 public function saveLendPref()
 {
     $id = Auth::user()->id;
     $loanApp = LoanApp::where('user_id', '=', $id)->get();
     $profile = UserProfile::where('id', '=', $id)->first();
     $financial = FinancialProfile::where('user_id', $id)->first();
     $lender_prefers = LenderPref::firstOrNew(array('user_id' => $id));
     $lender_prefers->min_amount = Input::get('minLoan');
     $lender_prefers->min_term = Input::get('minTerm');
     $lender_prefers->min_rate = Input::get('minRate');
     $lender_prefers->max_amount = Input::get('maxLoan');
     $lender_prefers->max_term = Input::get('maxTerm');
     $lender_prefers->max_rate = Input::get('maxRate');
     $lender_prefers->save();
     $results = $this->search();
     $pdata = $profile->getProfile($id);
     // method defined in its model
     $fdata = $financial->getFinancialProfile($id);
     // methd defined in its model
     $bids = DB::table('bids')->join('loan_app', 'bids.loan_id', '=', 'loan_app.loan_id')->join('profile', 'profile.id', '=', 'loan_app.user_id')->select('bid_amount', 'pref_rate', 'term', 'purpose', 'fname', 'lname')->orderBy('bid_date', 'DESC')->get();
     return View::make('myprofiles', compact('bids', 'pdata', 'fdata', 'results', 'loanApp'));
     /*	return Redirect::route('myprofile');   */
 }
 public function previewContract($loan_id)
 {
     //  Is what I did last night?  I hope so, else I'm lost.
     $id = Auth::user()->id;
     $usermail = Auth::user()->email;
     $profile = UserProfile::where('id', '=', $id)->first();
     // Retreive from the DB details about loan, where loanid = input for function and user_id = id of person logged in.
     // This should return object.
     $loan = DB::table('loan_app')->select('amount', 'term', 'pref_rate', 'purpose', 'progress', 'loan_id', 'match_date')->where('user_id', '=', $id)->where('loan_id', '=', $loan_id)->orderBy('match_date', 'DESC')->first();
     // Run the getLenders function and store the returned value as $lenders.
     $lenders = $this->getLenders($loan_id);
     // If there is no value for lenders...
     if (empty($lenders)) {
         // fail and redirect somewhere else
         return Redirect::route('mytransaction')->with('message', 'Could not find lenders for this loan request');
     }
     $contract = Contract::firstOrNew(array('offer_id' => Input::get('offer_id', $loan_id)));
     if (!$contract->getAttribute('offer_id')) {
         return Redirect::to('mytransaction')->with('message', 'No dice!');
     }
     $success = null;
     $errors = array();
     if (Request::isMethod('post')) {
         // update contract record with new status
         if (Input::get('i_agree') !== null) {
             $contract->setAttribute('status', 'complete');
             if ($contract->save()) {
                 $success = 'Your contract was finalised';
             } else {
                 $errors[] = 'Your contract was not finalised';
             }
         }
     }
     $backurl = route('createContract', array($loan_id));
     return View::make('previewContract', compact('loan', 'profile', 'success', 'errors', 'contract', 'lenders', 'backurl'));
 }
 public function logHwork()
 {
     $id = Auth::user()->id;
     $usermail = Auth::user()->email;
     // $photos = Auth::user()->photos()->get();
     $profile = UserProfile::where('id', '=', $id)->first();
     $financial = FinancialProfile::where('user_id', $id)->first();
     // think about cacahe below two queries
     $pdata = $profile->getProfile($id);
     //  method defiend in its model
     return View::make('logHworks', compact('id', 'bids', 'pdata', 'fdata', 'loanApp', 'allLoan', 'age', 'comments'));
 }