public static function clientByBranch($id) { $list = \Friends::where('parent_id', '=', $id)->get(); return $list; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { //transaction strats \DB::beginTransaction(); //delete user in user table $userDel = \User::find($id); if (!$userDel->delete()) { \DB::rollback(); return \Redirect::back()->with('error', 'Failed to delete'); } //delete user from friends table $friendDel = \Friends::where('child_id', '=', $id)->first(); if (!$friendDel->delete()) { \DB::rollback(); return \Redirect::back()->with('error', 'Failed to delete'); } //delete clients company $companyDel = \Company::where('user_id', '=', $id)->first(); if (!$companyDel->delete()) { \DB::rollback(); return \Redirect::back()->with('error', 'Failed to delete'); } else { \DB::commit(); return \Redirect::back()->with('success', 'Successfully deleted'); } }
/** * Display a listing of the resource. * * @return Response */ public function index() { $uId = \Auth::user()->id; $month = \Input::get('month'); $year = \Input::get('year'); $emp_type = \Input::get('emp_type'); $client = \Input::get('clientId'); $empty = \User::where('id', '=', 0)->paginate(20); if (preg_match("/^(0[1-9]|1[0-2])\$/", $month) && preg_match("/^[0-9]{4}\$/", $year) && $emp_type) { $date = "{$year}-{$month}-01"; if ($emp_type == 'outsource') { if (is_numeric($client)) { $check = \Friends::where('child_id', '=', $client)->where('parent_id', '=', $uId)->first(); if ($check) { $emps = \User::whereHas('empJobDetail', function ($q) use($client) { $q->where('emp_type', '=', 'outsource'); $q->where('client_id', '=', $client); })->get(); // get selected ids in array format $ids = array_pluck($emps, 'id'); if ($ids) { foreach ($ids as $id) { if (\EmpAttendance::where('emp_id', '=', $id)->where('attend_date', '=', "{$date}")->first()) { // skip } else { \EmpAttendance::insert(array('emp_id' => $id, 'attend_date' => $date)); } } $employees = \EmpAttendance::whereIn('emp_id', $ids)->where('attend_date', '=', "{$date}")->paginate(20); return \View::make('branch/attendance.emp_attendance')->with('list', $employees)->with(\Input::flash()); } else { return \View::make('branch/attendance.emp_attendance')->with('list', $empty)->with(\Input::flash()); } } else { return \View::make('branch/attendance.emp_attendance')->with('list', $empty)->with(\Input::flash()); } } } else { $emps = \User::whereHas('empJobDetail', function ($q) use($uId) { $q->whereHas('branch', function ($s) use($uId) { $s->where('branch_id', '=', $uId); })->where('emp_type', '=', 'inhouse'); })->get(); $ids = array_pluck($emps, 'id'); if ($ids) { foreach ($ids as $id) { if (\EmpAttendance::where('emp_id', '=', $id)->where('attend_date', '=', "{$date}")->first()) { // skip } else { \EmpAttendance::insert(array('emp_id' => $id, 'attend_date' => $date)); } } $employees = \EmpAttendance::whereIn('emp_id', $ids)->where('attend_date', '=', "{$date}")->paginate(20); return \View::make('branch/attendance.emp_attendance')->with('list', $employees)->with(\Input::flash()); } else { return \View::make('branch/attendance.emp_attendance')->with('list', $empty)->with(\Input::flash()); } } } else { return \View::make('branch/attendance.emp_attendance')->with('list', $empty)->with(\Input::flash()); } }
public function clientByBranch() { $id = \Input::get('id'); $list = \Friends::where('parent_id', '=', $id)->get(); $option = "<option value=''>----Select Client-----</option><option value='in-house'>In House </option>"; foreach ($list as $value) { $option .= "<option value='{$value->child_id}'>" . $value->user->company->company_name . "</option>"; // $json[$value->child_id]=$value->user->company->company_name; } echo $option; return; }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $uId = \Auth::user()->id; $emp = \User::where('id', '=', $id)->first(); if ($emp) { $dept = \Department::get(); $client = \Friends::where('parent_id', '=', $uId)->get(); return \View::make('branch/emp.edit')->with('dept', $dept)->with('emp', $emp)->with('client', $client); } else { \App::abort(404); } }