public function index()
 {
     $heads = Head::lists('name', 'id');
     $notes = Note::latest('id')->paginate(20);
     $bizs = Busines::all();
     $orgs = Organization::all();
     $forumHeads = forumHead::all();
     return view('admin.index', compact('notes', 'bizs', 'orgs', 'forumHeads', 'heads'));
 }
 public function postFinancialStatus(Request $request)
 {
     $data = $request->all();
     $latest = FinancialStatus::latest('created_at')->first();
     $event_id = Event::latest('id')->first()->id;
     $head_id = Head::where('event_id', $event_id)->where('position', 'Finance Committee Head')->first()->id;
     $data['weekly_income'] = $data['cash_in'] - $data['cash_out'];
     $data['cash_in_hand'] = $latest->cash_in_hand + $data['weekly_income'];
     $data['target_budget'] = $latest['target_budget'];
     $data['event_id'] = $event_id;
     $data['head_id'] = $head_id;
     FinancialStatus::create($data);
     return redirect("/");
 }
 function getTask()
 {
     $user = \Auth::user();
     $events = Event::all();
     $event = Event::latest('id')->first();
     $tasks = Task::all();
     $categories = array('Pending', 'In-progress', 'Delayed', 'Finished');
     //Array of head->id of user
     $heads_comm = Head::where('event_id', $event->id)->where('user_id', $user->id)->get(array('comm_id'))->toArray();
     //members of committee
     $mem = Member::whereIn('comm_id', $heads_comm)->get(array('user_id'))->toArray();
     $members = User::whereIn('id', $mem)->get();
     //committees where user is head
     $committees = Committee::whereIn('id', $heads_comm)->get();
     return view('pages/task', compact('user', 'members', 'events', 'event', 'committees', 'tasks', 'categories'));
 }
 public function getBalance()
 {
     $user = \Auth::user();
     $curr_event = Event::latest('id')->first();
     $is_head = Head::where('event_id', $curr_event->id)->where('user_id', $user->id)->first();
     if ($is_head->position == "Finance Committee Head") {
         $is_head = true;
     } else {
         $is_head = false;
     }
     if (!$is_head) {
         return redirect("/");
     }
     $users = User::where('standing', 'active')->oldest('lname')->get();
     return view('pages/finance', compact('user', 'users'));
 }
 public function postHead(Request $request)
 {
     $head = $request->all();
     Head::create($head);
     return redirect('/admin');
 }
 public function run()
 {
     FinancialStatus::create(['id' => '1', 'cash_in' => '2000', 'cash_out' => '1500', 'weekly_income' => '500', 'payables' => '4900', 'cash_in_hand' => '7543.50', 'target_budget' => '23543.50', 'event_id' => '2', 'head_id' => Head::where('event_id', 2)->where('position', 'Finance Committee Head')->first()->id]);
     $this->call('EventShoutsSeeder');
 }
 public function getId($id)
 {
     $users = User::all();
     $user = $this->getUser();
     $curr_event = Event::where('id', $id)->first();
     $all_comm = Committee::all();
     $committees = Committee::where('event_id', $curr_event->id)->get();
     $comm_array = Committee::where('event_id', $curr_event->id)->get(array('id'))->toArray();
     $events = Event::all();
     $tasks = Task::where('assigned_to', $user['id'])->whereIn('comm_id', $comm_array)->get();
     //tasks assigned to current user
     $all_tasks = Task::all();
     $categories = array('Pending', 'In-progress', 'Delayed', 'Finished');
     $comments = Comment::all();
     //get current event id
     $curr_event_id = $curr_event->id;
     //check if current user is upper head
     //get all heads of current event
     $heads = Head::where('event_id', $curr_event_id)->where('user_id', $user->id)->get();
     //get all comm_id(as array) in the current event where current user is a head
     $heads_comm = Head::where('event_id', $curr_event_id)->where('user_id', $user['id'])->get(array('comm_id'))->toArray();
     //members of committee
     $mem = Member::whereIn('comm_id', $heads_comm)->get(array('user_id'))->toArray();
     $members = User::whereIn('id', $mem)->get();
     //get all committees in the current event where current user is a head
     $head_committees = Committee::whereIn('id', $heads_comm)->get();
     //current user is a head
     $heads_comm = Head::where('user_id', $user['id'])->get();
     //committees where current user is a member
     $mem_comm = Member::where('user_id', $user['id'])->get();
     $url = "pages/profile";
     //check if curret user is admin
     if ($user->id == 1) {
         return redirect('/admin/');
     }
     //check if current user is OAH
     if ($curr_event->oah_id == $user->id) {
         $url = "pages/oah";
     }
     //return heads page if user is lower head
     if ($heads != "[]") {
         $url = "pages/heads";
     }
     if ($user->standing == "unconfirmed") {
         $url = "pages/oops";
     }
     echo $url;
     return view($url, compact('users', 'user', 'events', 'curr_event', 'all_comm', 'committees', 'tasks', 'all_tasks', 'categories', 'comments', 'head_committees', 'heads_comm', 'mem_comm', 'members'));
 }