|
|
|
@ -11,7 +11,7 @@ use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Laravel\Lumen\Auth\Authorizable; |
|
|
|
|
use Carbon\Carbon; |
|
|
|
|
|
|
|
|
|
class User extends Model implements AuthenticatableContract, AuthorizableContract,JWTSubject |
|
|
|
|
class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject |
|
|
|
|
{ |
|
|
|
|
use Authenticatable, Authorizable, HasFactory; |
|
|
|
|
|
|
|
|
@ -24,7 +24,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|
|
|
|
protected $fillable = [ |
|
|
|
|
'name', 'email', 'role_id', 'username', 'session_login', 'phone_number', 'email', 'address', |
|
|
|
|
'fcm_token', 'gender', 'birth_place', 'birth_date', 'blood_type', 'ktp_number', 'working_hours', |
|
|
|
|
'created_at', 'created_by', 'updated_at', 'updated_by', 'status_resource' |
|
|
|
|
'created_at', 'created_by', 'updated_at', 'updated_by', 'status_resource', 'discount_id' |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
const CREATED_AT = 'created_at'; |
|
|
|
@ -71,44 +71,42 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|
|
|
|
* @return array of carbon or NULL in case HOLIDAY |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
public function getWorkingTime(Carbon $ts, $f = "08:00", $t = "17:00", $tz = self::DEFAULT_TZ) |
|
|
|
|
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) |
|
|
|
|
"from" => Carbon::createFromTimeString($f, $tz), |
|
|
|
|
"to" => Carbon::createFromTimeString($t, $tz) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$userShift = UserShift::where('user_id', ) |
|
|
|
|
$userShift = UserShift::where('user_id',) |
|
|
|
|
->orderByDesc('from_date') |
|
|
|
|
->first(); |
|
|
|
|
|
|
|
|
|
$shift = null; |
|
|
|
|
if ($userShift !== null) |
|
|
|
|
{ |
|
|
|
|
if ($userShift !== null) { |
|
|
|
|
$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; |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($shiftId === null) { |
|
|
|
@ -123,8 +121,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($shift !== null) |
|
|
|
|
{ |
|
|
|
|
if ($shift !== null) { |
|
|
|
|
$from = Carbon::createFromTimeString($shift->start_time, $tz) |
|
|
|
|
->subMinutes($shift->flex_time_minute); |
|
|
|
|
$to = Carbon::createFromTimeString($shift->end_time, $tz) |
|
|
|
@ -146,20 +143,18 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|
|
|
|
/** |
|
|
|
|
* Get presence status |
|
|
|
|
*/ |
|
|
|
|
public function presenceStatus(Carbon $at = null, $tz = self::DEFAULT_TZ) |
|
|
|
|
public function presenceStatus(Carbon $at = null, $tz = self::DEFAULT_TZ) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
$ts = $at; |
|
|
|
|
if ($at !== null) |
|
|
|
|
{ |
|
|
|
|
if ($at !== null) { |
|
|
|
|
$ts = Carbon::now($tz); |
|
|
|
|
} |
|
|
|
|
$tsSec = $ts->secondsSinceMidnight(); |
|
|
|
|
|
|
|
|
|
$status = ""; |
|
|
|
|
$wt = $this->getWorkingTime($ts, $tz); |
|
|
|
|
if ($wt === null) |
|
|
|
|
{ |
|
|
|
|
if ($wt === null) { |
|
|
|
|
$status = self::HOLIDAY; |
|
|
|
|
} else { |
|
|
|
|
$from = $wt->from; |
|
|
|
@ -168,7 +163,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|
|
|
|
$tsTo = $to->secondsSinceMidnight(); |
|
|
|
|
|
|
|
|
|
if ($from->greaterThan($to)) { |
|
|
|
|
$tsMid = 24*60*60 - $tsFrom; |
|
|
|
|
$tsMid = 24 * 60 * 60 - $tsFrom; |
|
|
|
|
if ($tsSec >= $tsFrom || $tsSec < $tsTo) { |
|
|
|
|
$status = self::INSIDE; |
|
|
|
|
} else { |
|
|
|
@ -194,10 +189,10 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return array( |
|
|
|
|
"status"=>$status, |
|
|
|
|
"ts" => $ts, |
|
|
|
|
"status" => $status, |
|
|
|
|
"ts" => $ts, |
|
|
|
|
"clock_in" => $clockIn, |
|
|
|
|
"clock_out" => $clockOut |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|