public function store(Request $request)
 {
     //dd($request->all());
     $roster = new Roster();
     $roster->course_id = $request->input('course_id');
     $roster->user_id = $request->input('user_id');
     $roster->save();
     return redirect('courses');
 }
Beispiel #2
0
 public static function shifts($user_id, $company_id, $start, $end)
 {
     $arr = [];
     $rosters = Roster::whereHas('users', function ($q) use($user_id) {
         $q->where('users.id', $user_id)->where('roster_user.status', '=', 'accepted');
     })->whereBetween('start_time', [$start, $end])->where('company_id', $company_id)->get();
     foreach ($rosters as $roster) {
         $roster_pivot = $roster->users()->where('users.id', $user_id)->first()->pivot;
         //return var_dump(Roster::payment($roster->id, $user_id, $company_id));
         $amount = Roster::payment($roster->id, $user_id, $company_id)['payment'];
         array_push($arr, ['start' => $roster->start_time, 'end' => $roster->end_time, 'real_start' => $roster_pivot->real_start_time, 'real_end' => $roster_pivot->real_end_time, 'amount' => $amount, 'id' => $roster->id, 'address' => $roster->address]);
     }
     return $arr;
 }
 public function groups()
 {
     $bp = BusinessPlan::all();
     $bpid = count($bp);
     $groups = Group::all();
     $tasks = array();
     $actions = array();
     foreach (BusinessPlan::all() as $x) {
         array_push($tasks, DB::select("select t.* from tasks t, actions a, objectives o, goals g, business_plans b where t.action_id = a.id and a.objective_id = o.id and o.goal_id = g.id and g.bpid = b.id and b.id = {$x->id}"));
         array_push($actions, DB::select("select a.* from actions a, objectives o, goals g, business_plans b where a.objective_id = o.id and o.goal_id = g.id and g.bpid = b.id and b.id = {$x->id}"));
     }
     $users = User::all();
     $rosters = Roster::all();
     $businessPlans = BusinessPlan::lists('name', 'id');
     return view('groups', compact('groups', 'actions', 'tasks', 'users', 'rosters', 'businessPlans', 'bpid'));
 }
Beispiel #4
0
 public static function payment(int $id, $user_id, string $company_id) : array
 {
     $company_shift_start = Company::where('id', $company_id)->select('shift_day_start as day', 'shift_night_start as night')->first();
     $roster = Roster::find($id)->users()->where('users.id', $user_id)->first();
     if (count($roster) > 0 && $roster->pivot->real_start_time != null && $roster->pivot->real_start_time != null) {
         $start_str = strtotime($roster->pivot->real_start_time);
         $end_str = strtotime($roster->pivot->real_end_time);
         $arr_times = [];
         $payment = 0;
         $time = 0;
         for ($i = $start_str; $i <= $end_str; $i += 300) {
             $current_checking_time = date("Y-m-d H:i:s", $i);
             $custom_payment_amount = Payment::custom($current_checking_time);
             if ($custom_payment_amount == 0) {
                 $id = date("N", $i) - 1;
                 if (Common::isTimeBetween(date("H:i:s", $i), $company_shift_start->day, $company_shift_start->night)) {
                     $id .= "_day";
                 } else {
                     $id .= "_night";
                 }
                 if ($roster->pivot->is_supervisor == 1) {
                     $id .= "_supervisor";
                 } else {
                     $id .= "_worker";
                 }
                 !isset($arr_times[$id]) ? $arr_times[$id] = 1 : ($arr_times[$id] += 1);
             } else {
                 $payment += $custom_payment_amount * (1 / 12);
                 $time += 1 / 12;
             }
         }
         foreach ($arr_times as $key => $time_count) {
             list($day, $period, $type) = explode('_', $key);
             $amount = Payment::week($day, $period, $type, $company_id);
             $payment += $amount * (5 / 60 * $time_count);
             $time += $time_count;
             //return var_dump($amount);
         }
         return ['payment' => number_format((double) $payment, 2, '.', '') ?? 0, 'time' => $time];
     }
     return ['payment' => 0, 'time' => 0];
 }
 public function update(Request $request, $user_id)
 {
     $this->validate($request, ['real_start.*' => ['regex:/[0-9]{2}\\/[0-9]{2}\\/[0-9]{4}\\s[0-9]{1,2}:[0-9]{2}\\s(AM|PM)\\s-\\s[0-9]{2}\\/[0-9]{2}\\/[0-9]{4}\\s[0-9]{1,2}:[0-9]{2}\\s(AM|PM)/'], 'real_end.*' => ['regex:/[0-9]{2}\\/[0-9]{2}\\/[0-9]{4}\\s[0-9]{1,2}:[0-9]{2}\\s(AM|PM)\\s-\\s[0-9]{2}\\/[0-9]{2}\\/[0-9]{4}\\s[0-9]{1,2}:[0-9]{2}\\s(AM|PM)/']]);
     $start_times_arr = $request->get('real_start');
     $end_times_arr = $request->get('real_end');
     if (count(array_filter($start_times_arr)) > 0) {
         foreach ($start_times_arr as $roster_id => $time) {
             $start = $time;
             $end = $end_times_arr[$roster_id];
             $roster = Roster::find($roster_id)->users();
             //return var_dump($roster->pivot);
             if ($start != null && $start != "") {
                 $roster->updateExistingPivot($user_id, ['real_start_time' => Common::formatDateTimeForSQL($start)]);
             }
             if ($end != null && $end != "") {
                 $roster->updateExistingPivot($user_id, ['real_end_time' => Common::formatDateTimeForSQL($end)]);
             }
             //$roster->save();
         }
     }
     return redirect()->back()->with(['message' => 'Data successfully updated']);
 }
 public function show($id = null)
 {
     if ($id == null) {
         $id = Auth::user()->id;
     }
     $user = User::find($id);
     $notification_count = Notification::count($id);
     $notification_obj = Notification::read($id, true, 6);
     $notification_list = Notification::format($notification_obj);
     $messages = Messages::topUnseen(5);
     $count_of_rosters = Roster::whereBetween('start_time', [date("Y-m-01 00:00:00"), date("Y-m-d 23:59:59")])->whereHas('users', function ($q) use($id) {
         $q->where('users.id', '=', $id);
     })->count();
     $payment_data = Payment::singleUser(Auth::user(), date("Y-m-01 00:00:00"), date("Y-m-d 23:59:59"));
     return view('users.view')->with(['user' => $user, 'notification_count' => $notification_count, 'notification_list' => $notification_list, 'messages' => $messages, 'count_of_rosters' => $count_of_rosters, 'hours_last_month' => $payment_data['time'], 'amount_last_month' => $payment_data['salary']]);
 }
Beispiel #7
0
 public function showByDate($year, $month)
 {
     $events = Roster::withYear($year)->withMonth($month)->first()->events();
     return $this->respond($events);
 }
 public function addUsers($id, Request $request)
 {
     $users = $request->input('users');
     $roster_data = Roster::where('id', '=', $id)->first();
     $roster = Roster::find($id)->users();
     foreach ($users as $user) {
         $roster->attach($user);
         Notification::add($user, 'CREATE_EVENT', ['start' => Common::formatDateTimeForSQL($roster_data->start_time), 'end' => Common::formatDateTimeForSQL($roster_data->end_time), 'admin_id' => Auth::user()->id]);
     }
     return response()->json(Roster::where('id', $id)->with('users')->first()->toArray()['users'], 200);
 }
Beispiel #9
0
 public function toggleRosterStatus(Roster $roster)
 {
     $roster->status = $roster->status == 'open' ? 'closed' : 'open';
     $roster->save();
     return $this->respond($roster);
 }