示例#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]);
 }
示例#3
0
 public function store(HolidayRequest $request, Holiday $holiday)
 {
     if (!Entrust::can('create_holiday')) {
         return redirect('/dashboard')->withErrors(config('constants.NA'));
     }
     $dates = explode(',', $request->input('date'));
     $data = $request->all();
     foreach ($dates as $date) {
         $holiday_exists = Holiday::where('date', '=', $date)->count();
         if (!$holiday_exists) {
             $holiday = new Holiday();
             $holiday->date = $date;
             $holiday->holiday_description = $request->input('holiday_description');
             $holiday->save();
             Helper::storeCustomField($this->form, $holiday->id, $data);
         }
     }
     $activity = 'Added new holiday';
     Activity::log($activity);
     return redirect()->back()->withSuccess(config('constants.ADDED'));
 }
 /**
  * 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');
 }
 public function todayIsHoliday()
 {
     if (Carbon::today()->format('l') == 'Friday' || Holiday::where('holidate', Carbon::today())->first() != null) {
         return true;
     } else {
         return false;
     }
 }
示例#6
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);
 }
示例#7
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;
         }
     }
 }