getKey(); } /** * Return a key value array, containing any custom claims to be added to the JWT. * * @return array */ public function getJWTCustomClaims() { return []; } /// --- belum terpakai, sementara pakai API golang --- /** * Get working hours for given timestamp * * @return array of carbon or NULL in case HOLIDAY */ public function getWorkingTime(Carbon $ts, $f = "08:00", $t = "17:00", $tz = self::DEFAULT_TZ) { $workingTime = array( "from"=> Carbon::createFromTimeString($f, $tz), "to"=> Carbon::createFromTimeString($t, $tz) ); // get Shift assignment $userShift = UserShift::where('user_id', ) ->orderByDesc('from_date') ->first(); // HAS SHIFT $shift = null; if ($userShift !== null) { // get date //$ts = Carbon::parse($strTs); $shiftId = null; switch ($ts->shortEnglishDayOfWeek) { case "Mon": $shiftId = $userShift->mon_shift_id; break; case "Tue": $shiftId = $userShift->tue_shift_id; break; case "Wed": $shiftId = $userShift->wed_shift_id; break; case "Thu": $shiftId = $userShift->thu_shift_id; break; case "Fri": $shiftId = $userShift->fri_shift_id; break; case "Sat": $shiftId = $userShift->sat_shift_id; break; case "Sun": $shiftId = $userShift->sun_shift_id; break; } // Holiday if ($shiftId === null) { return null; } $shift = Shift::where('id', $shiftId)->first(); } else { // get default shift time (NON-SHIFT) $shift = Shift::where('is_non_shift', true) ->orderByDesc('created_at') ->first(); } // TODO: calendar holiday // assign shift time if ($shift !== null) { $from = Carbon::createFromTimeString($shift->start_time, $tz) ->subMinutes($shift->flex_time_minute); $to = Carbon::createFromTimeString($shift->end_time, $tz) ->addMinutes($shift->flex_time_minute); /* if ($to->lessThan($from)) { $to->addDay(); } */ $workingTime['from'] = $from; $workingTime['to'] = $to; } // return working time return $workingTime; } /** * Get presence status */ public function presenceStatus(Carbon $at = null, $tz = self::DEFAULT_TZ) { // response // INSIDE, OUTSIDE, HOLIDAY $ts = $at; if ($at !== null) { $ts = Carbon::now($tz); } $tsSec = $ts->secondsSinceMidnight(); $status = ""; $wt = $this->getWorkingTime($ts, $tz); if ($wt === null) { $status = self::HOLIDAY; } else { $from = $wt->from; $to = $wt->to; $tsFrom = $from->secondsSinceMidnight(); $tsTo = $to->secondsSinceMidnight(); // working hours with different date // e.g. 22:00 - 06:00 (nextday) if ($from->greaterThan($to)) { $tsMid = 24*60*60 - $tsFrom; if ($tsSec >= $tsFrom || $tsSec < $tsTo) { $status = self::INSIDE; } else { $status = self::OUTSIDE; } } else { if ($tsSec < $tsFrom || $tsSec > $tsTo) { $status = self::OUTSIDE; } else { $status = self::INSIDE; } } } // Get clock-in/out $clockIn = null; $clockOut = null; $inout = Presence::where('user_id', $this->id) ->orderByDesc('clock_in') ->first(); if ($inout !== null) { $clockIn = Carbon::parse($inout->clock_in, $tz); $clockOut = Carbon::parse($inout->clock_out, $tz); } return array( "status"=>$status, "ts" => $ts, "clock_in" => $clockIn, "clock_out" => $clockOut ); } }