Example #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     //check if have entry for today
     //check if locked
     //if good kaliwali
     //else populate with zeroes
     //then lock
     if (Attendance::latest('att_date')->first()->att_date != Carbon::today()) {
         $currentDate = new Attendance();
         $currentDate->att_date = Carbon::today();
         $holiday = 0;
         if (Carbon::today()->format('l') == 'Friday' || Holiday::where('holidate', Carbon::today())->first() != null) {
             $holiday = 1;
         }
         $currentDate->holiday = $holiday;
         $currentDate->save();
     }
     foreach (Site::all() as $site) {
         foreach ($site->labor as $labor) {
             if ($labor->attendance()->where('att_date', Carbon::today()->format('Y-m-d G:i:s'))->first() != null) {
                 $labor->attendance()->where('att_date', Carbon::today()->format('Y-m-d G:i:s'))->first()->pivot->update(['locked' => 'true']);
             } else {
                 Attendance::latest('att_date')->first()->labor()->attach($labor->id);
                 $att = $labor->attendance()->where('att_date', Carbon::today()->format('Y-m-d G:i:s'))->first();
                 $att->pivot->locked = 'true';
                 $att->pivot->attended = $att->holiday == 1 ? 1 : 0;
                 $att->pivot->ot = 0;
                 $att->pivot->bot = 0;
                 $att->pivot->site = $labor->site->code;
                 $att->pivot->save();
             }
         }
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //check that the models work
     $escape_id = \App\Escape::where('name', '=', 'Great Barrier Reef')->pluck('id');
     $holiday_id = \App\Holiday::where('name', '=', 'holiday in Cairns')->pluck('id');
     DB::table('escape_holiday')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'escape_id' => $escape_id, 'holiday_id' => $holiday_id]);
     $escape_id = \App\Escape::where('name', '=', 'Bondi Beach')->pluck('id');
     $holiday_id = \App\Holiday::where('name', '=', 'holiday in Sydney')->pluck('id');
     DB::table('escape_holiday')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'escape_id' => $escape_id, 'holiday_id' => $holiday_id]);
     $escape_id = \App\Escape::where('name', '=', 'cuddle Koalas')->pluck('id');
     $holiday_id = \App\Holiday::where('name', '=', 'Australian tour')->pluck('id');
     DB::table('escape_holiday')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'escape_id' => $escape_id, 'holiday_id' => $holiday_id]);
     $escape_id = \App\Escape::where('name', '=', 'Pebbly Beach')->pluck('id');
     $holiday_id = \App\Holiday::where('name', '=', 'holiday in Sydney')->pluck('id');
     DB::table('escape_holiday')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'escape_id' => $escape_id, 'holiday_id' => $holiday_id]);
     $escape_id = \App\Escape::where('name', '=', 'hartlies crocodile adventures')->pluck('id');
     $holiday_id = \App\Holiday::where('name', '=', 'holiday in Cairns')->pluck('id');
     DB::table('escape_holiday')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'escape_id' => $escape_id, 'holiday_id' => $holiday_id]);
 }
Example #3
0
 public function index(Request $request)
 {
     $start_date = $request->input('start_date') ?: date('Y-m-d', strtotime('-30 days'));
     $end_date = $request->input('end_date') ?: date('Y-m-d', strtotime(date('Y-m-d')));
     if (Entrust::hasRole('user')) {
         return redirect('/')->withErrors(config('constants.NA'));
     }
     $user_count = \App\User::with('roles')->whereHas('roles', function ($query) {
         $query->whereName('user');
     })->where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->count();
     $staff_count = \App\User::with('roles')->whereHas('roles', function ($query) {
         $query->where('name', '!=', 'user');
     })->where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->count();
     $ticket_count = \App\Ticket::where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->count();
     $closed_ticket_count = \App\Ticket::where('ticket_status', '=', 'close')->where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->count();
     $closed_ticket_percentage = $ticket_count > 0 ? round($closed_ticket_count / $ticket_count * 100, 2) : 0;
     $ticket_status_stats = \App\Ticket::select('ticket_status', DB::raw('count(*) as total'))->where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->groupBy('ticket_status')->get();
     $status_stats = array();
     foreach ($ticket_status_stats as $stat) {
         $status_stats[] = array('label' => Helper::toWord($stat->ticket_status), 'value' => $stat->total);
     }
     $ticket_priority_stats = \App\Ticket::select('ticket_priority', DB::raw('count(*) as total'))->where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->groupBy('ticket_priority')->get();
     $priority_stats = array();
     foreach ($ticket_priority_stats as $stat) {
         $priority_stats[] = array('label' => Helper::toWord($stat->ticket_priority), 'value' => $stat->total);
     }
     $ticket_type_status = \App\Ticket::select('ticket_type_id', DB::raw('count(*) as total'))->where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->groupBy('ticket_type_id')->get();
     $type_stats = array();
     foreach ($ticket_type_status as $stat) {
         $type_stats[] = array('label' => Helper::toWord($stat->TicketType->ticket_type_name), 'value' => $stat->total);
     }
     $ticket_department_stats = \App\Ticket::select('department_id', DB::raw('count(*) as total'))->where('created_at', '>=', $start_date)->where('created_at', '<=', $end_date)->groupBy('department_id')->get();
     $department_stats = array();
     foreach ($ticket_department_stats as $stat) {
         $department_stats[] = array('label' => Helper::toWord($stat->Department->department_name), 'value' => $stat->total);
     }
     $users = \App\User::with('roles')->whereHas('roles', function ($query) {
         $query->where('name', '!=', 'user');
     })->where('id', '!=', Auth::user()->id)->get();
     $user_list = array();
     foreach ($users as $user) {
         $user_list[$user->id] = $user->name . ' (Department : ' . $user->Profile->Department->department_name . ')';
     }
     $query = DB::table('activity_log')->join('users', 'users.id', '=', 'activity_log.user_id')->select(DB::raw('name,activity_log.created_at AS created_at,text,user_id'));
     if (!Entrust::hasRole('admin')) {
         $query->where('user_id', '=', Auth::user()->id);
     }
     $activities = $query->latest()->limit(100)->get();
     $holidays = \App\Holiday::all();
     $todos = \App\Todo::where('user_id', '=', Auth::user()->id)->orWhere(function ($query) {
         $query->where('user_id', '!=', Auth::user()->id)->where('visibility', '=', 'public');
     })->get();
     $events = array();
     foreach ($holidays as $holiday) {
         $start = $holiday->date;
         $title = 'Holiday: ' . $holiday->holiday_description;
         $color = '#1e5400';
         $events[] = array('title' => $title, 'start' => $start, 'color' => $color);
     }
     foreach ($todos as $todo) {
         $start = $todo->date;
         $title = 'To do: ' . $todo->todo_title . ' ' . $todo->todo_description;
         $color = '#ff0000';
         $url = '/todo/' . $todo->id . '/edit';
         $events[] = array('title' => $title, 'start' => $start, 'color' => $color, 'url' => $url);
     }
     $colors = ['#5CB85C', '#FFD600', '#D10D0D', '#1A89E8', '#458b00', '#f85931', '#ce1836', '#009989', '#00688b', '#8b1a1a'];
     shuffle($colors);
     $status_colors = $colors;
     shuffle($colors);
     $priority_colors = $colors;
     shuffle($colors);
     $type_colors = $colors;
     shuffle($colors);
     $department_colors = $colors;
     $assets = ['calendar', 'graph'];
     return view('dashboard', compact('user_count', 'staff_count', 'assets', 'activities', 'user_list', 'holidays', 'events', 'ticket_count', 'closed_ticket_percentage', 'status_stats', 'priority_stats', 'type_stats', 'department_stats', 'status_colors', 'priority_colors', 'type_colors', 'department_colors', 'start_date', 'end_date'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($date)
 {
     $holiday = Holiday::where('holidate', $date)->first();
     $holiday->delete();
     flash('Successfully deleted');
     return redirect('holiday');
 }
Example #5
0
 public function postDelete(Request $request)
 {
     //gets the holiday that the escape belongs to
     $holiday = \App\Holiday::find($request->holiday_id);
     //loads the escape to be delete
     $escapeToDelete = \App\Escape::find($request->id);
     //detaches the escape from the holiday
     $holiday->escapes()->detach($request->id);
     //deletes the escape
     $escapeToDelete->delete();
     //load the holiday with its escapes
     $holidayWithEscapes = \App\Holiday::with('escapes')->where('id', '=', $request->holiday_id)->get();
     return redirect('holiday/create');
 }
 public function getHolidays()
 {
     return Holiday::all();
 }
Example #7
0
 protected function setLogs($collection)
 {
     $this->holidays = Holiday::whereBetween('start', [$this->date_from, $this->date_to])->orWhereBetween('end', [$this->date_from, $this->date_to])->get();
     // dd($this->holidays->contains('start', '2015-08-30') || $this->holidays->contains('end', '2015-08-30'));
     foreach ($collection as $employees) {
         $userID = $employees->first()['user'];
         $employee = Employee::where('employee_id', $userID)->first();
         $currentDate = $this->date_from;
         $datesArray = [];
         $index = 0;
         do {
             //detecting absenses
             try {
                 $user = $employees[$index];
                 if (empty($employee)) {
                     break;
                 } else {
                     if (!$employee->shifts->isEmpty()) {
                         if ($currentDate != $user['date']) {
                             $newUser['user'] = $userID;
                             $newUser['date'] = $currentDate;
                             $newUser['attendance'] = null;
                             $this->store($newUser, $employee->shifts);
                             $currentDate = incrementDateByOneDay($currentDate);
                         } elseif ($currentDate == $user['date']) {
                             $this->store($user, $employee->shifts);
                             ++$index;
                             $currentDate = incrementDateByOneDay($currentDate);
                         }
                     } else {
                         break;
                     }
                 }
             } catch (ErrorException $ex) {
                 $newUser['user'] = $userID;
                 $newUser['date'] = $currentDate;
                 $newUser['attendance'] = null;
                 $this->store($newUser, $employee->shifts);
                 $currentDate = incrementDateByOneDay($currentDate);
             }
         } while ($currentDate <= $this->date_to);
     }
 }
 public function todayIsHoliday()
 {
     if (Carbon::today()->format('l') == 'Friday' || Holiday::where('holidate', Carbon::today())->first() != null) {
         return true;
     } else {
         return false;
     }
 }
Example #9
0
 public function postUpdate(Request $request)
 {
     $this->validate($request, ['name' => 'required|min:5', 'description' => 'required|min:5|max:256', 'due_date' => 'required|date']);
     //gets the holiday to be updated and loads the request data to the DB
     $holiday_to_update = \App\Holiday::where('id', '=', $request->id)->update(['name' => $request->name, 'description' => $request->description, 'due_date' => $request->due_date]);
     //retrieves the updated data from the db for display
     $holiday = \App\Holiday::find($request->id);
     return view('holidays.update')->with('holiday', $holiday);
 }
Example #10
0
 public static function calculateDueTime($time, $created_at)
 {
     $days = config('list.week');
     foreach ($days as $d) {
         $business_hour[$d]['start'] = config('config.default_working_start_time');
         $business_hour[$d]['end'] = config('config.default_working_end_time');
     }
     $business_hours = \App\BusinessHour::all();
     foreach ($business_hours as $hour) {
         $business_hour[$hour->day]['start'] = $hour->start;
         $business_hour[$hour->day]['end'] = $hour->end;
     }
     $holidays = \App\Holiday::where('date', '>=', date('Y-m-d', strtotime($created_at)))->lists('date')->all();
     while ($time > 0) {
         $date = isset($date) ? date('Y-m-d', strtotime($date . ' +1 day')) : $created_at;
         $day = date('l', strtotime($date));
         $end = date('Y-m-d', strtotime($date)) . ' ' . $business_hour[$day]['end'];
         $start = !isset($start) ? $date : date('Y-m-d', strtotime($date)) . ' ' . $business_hour[$day]['start'];
         if (in_array(date('Y-m-d', strtotime($date)), $holidays)) {
             continue;
         }
         $diff = round((strtotime($end) - strtotime($start)) / 60);
         if ($diff < 0) {
             $diff = 0;
         }
         if ($time <= $diff) {
             return date('Y-m-d, H:i', strtotime($start) + $time * 60);
         } else {
             $time -= $diff;
         }
     }
 }
Example #11
0
 public function destroy(Holiday $holiday)
 {
     if (!Entrust::can('delete_holiday')) {
         return redirect('/dashboard')->withErrors(config('constants.NA'));
     }
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     Helper::deleteCustomField($this->form, $holiday->id);
     $holiday->delete();
     return redirect('/holiday')->withSuccess(config('constants.DELETED'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $holiday = Holiday::findOrFail($id);
     $holiday->delete();
     return redirect('admin/holidays')->with('message', 'Holiday Member delete');
 }