public function evaluateWeight($id, $loan_id)
 {
     $finance = FinancialProfile::where('user_id', '=', $id)->first();
     $count = LoanApp::where('user_id', '=', $id)->count();
     $loan_app = LoanApp::where('loan_id', '=', $loan_id)->first();
     $current_bids = Bid::where('loan_id', '=', $loan_id)->count();
     $amout = $loan_app->amount;
     $term = $loan_app->term;
     $rate = $loan_app->pref_rate;
     $residence = $finance->residence_status;
     $year_income = $finance->monthly_income * 12;
     $home_loan = $finance->home_loan;
     $car_loan = $finance->car_loan;
     $other_loan = $finance->other_loan;
     $expense = $finance->loan_repayment;
     $other_exp = $finance->other_expense;
     $house_owner = 0;
     if (strcmp($residence, 'Mortage') == 0 || strcmp($residence, 'noMortage') == 0) {
         $house_owner = 1;
     }
     $property = $finance->property;
     $vehicle = $finance->vehicle;
     $share = $finance->share;
     $other_property = $finance->others;
     $active_loan = $total_liab = $home_loan + $car_loan + $other_loan;
     $income_debt_ratio = $year_income / (1 + $count + $total_liab);
     $total_assests = $property + $vehicle + $share + $other_property;
     $disposable_income = $year_income - $total_liab;
     $sum = $rate + $house_owner + $total_assests + $income_debt_ratio + $current_bids + $disposable_income;
     $weight = pow($sum, 1 / 6);
     //$loan_app-> weight = $weight;
     return $weight;
 }
 public function profile()
 {
     $id = Auth::user()->id;
     $usermail = Auth::user()->email;
     $profile = UserProfile::where('id', '=', $id)->first();
     $financial = FinancialProfile::where('user_id', $id)->first();
     $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();
     $loanApp = LoanApp::where('user_id', '=', $id)->get();
     $allLoan = DB::table('loan_app')->join('profile', 'loan_app.user_id', '=', 'profile.id')->select('profile.fname', 'profile.lname', 'loan_app.amount', 'loan_app.pref_rate', 'loan_app.term', 'loan_app.purpose', 'loan_app.loan_id')->where('loan_app.user_id', '<>', $id)->orderBy('weight', 'DESC')->get();
     // think about cacahe below two queries
     $pdata = $profile->getProfile($id);
     //  method defiend in its model
     $fdata = $financial->getFinancialProfile($id);
     // methd defined in its model
     return View::make('myprofiles', compact('bids', 'pdata', 'fdata', 'loanApp', 'allLoan'));
 }
 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 getFinancialProfile($user_id)
 {
     $Financial = FinancialProfile::where('user_id', $user_id)->first();
     $data = array('residence' => $Financial->residence_status, 'year_cur_addr' => $Financial->year_cur_addr, 'month_cur_addr' => $Financial->month_cur_addr, 'year_old_addr' => $Financial->year_old_addr, 'month_old_addr' => $Financial->month_old_addr, 'employ_status' => $Financial->employ_status, 'employer' => $Financial->employer, 'position' => $Financial->position, 'year_cur_job' => $Financial->year_cur_job, 'month_old_job' => $Financial->month_old_job, 'loan_repayments' => $Financial->loan_repayments, 'other_expense' => $Financial->other_expense, 'home_loan' => $Financial->home_loan, 'car_loan' => $Financial->car_loan, 'other_loan' => $Financial->other_loan, 'property' => $Financial->property, 'vehicle' => $Financial->vehicle, 'share' => $Financial->share, 'others' => $Financial->others, 'income' => $Financial->monthly_income);
     return $data;
 }
 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'));
 }