wahyuun
8 months ago
2 changed files with 215 additions and 215 deletions
@ -1,17 +1,17 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Models; |
namespace App\Models; |
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model; |
use Illuminate\Database\Eloquent\Model; |
||||||
|
|
||||||
class ProjectRole extends Model |
class ProjectRole extends Model |
||||||
{ |
{ |
||||||
protected $table = 'm_role_proyek'; |
protected $table = 'm_role_proyek'; |
||||||
|
|
||||||
const CREATED_AT = 'created_at'; |
const CREATED_AT = 'created_at'; |
||||||
const UPDATED_AT = 'updated_at'; |
const UPDATED_AT = 'updated_at'; |
||||||
|
|
||||||
protected $fillable = [ |
protected $fillable = [ |
||||||
'name', 'description', 'created_at', 'created_by', 'updated_at', 'updated_by' |
'name', 'description', 'created_at', 'created_by', 'updated_at', 'company_id', 'updated_by' |
||||||
]; |
]; |
||||||
} |
} |
||||||
|
@ -1,198 +1,198 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Models; |
namespace App\Models; |
||||||
|
|
||||||
use Tymon\JWTAuth\Contracts\JWTSubject; |
use Tymon\JWTAuth\Contracts\JWTSubject; |
||||||
use Illuminate\Auth\Authenticatable; |
use Illuminate\Auth\Authenticatable; |
||||||
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; |
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; |
||||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||||
use Illuminate\Database\Eloquent\Model; |
use Illuminate\Database\Eloquent\Model; |
||||||
use Laravel\Lumen\Auth\Authorizable; |
use Laravel\Lumen\Auth\Authorizable; |
||||||
use Carbon\Carbon; |
use Carbon\Carbon; |
||||||
|
|
||||||
class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject |
class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject |
||||||
{ |
{ |
||||||
use Authenticatable, Authorizable, HasFactory; |
use Authenticatable, Authorizable, HasFactory; |
||||||
|
|
||||||
protected $table = 'm_users'; |
protected $table = 'm_users'; |
||||||
/** |
/** |
||||||
* The attributes that are mass assignable. |
* The attributes that are mass assignable. |
||||||
* |
* |
||||||
* @var array |
* @var array |
||||||
*/ |
*/ |
||||||
protected $fillable = [ |
protected $fillable = [ |
||||||
'name', 'email', 'role_id', 'username', 'session_login', 'phone_number', 'email', 'address', |
'name', 'email', 'role_id', 'username', 'session_login', 'phone_number', 'email', 'address', |
||||||
'fcm_token', 'gender', 'birth_place', 'birth_date', 'blood_type', 'ktp_number', 'working_hours', |
'fcm_token', 'gender', 'birth_place', 'birth_date', 'blood_type', 'ktp_number', 'working_hours', |
||||||
'created_at', 'created_by', 'updated_at', 'updated_by', 'status_resource', 'discount_id' |
'created_at', 'created_by', 'updated_at', 'updated_by', 'status_resource', 'discount_id','company_id' |
||||||
]; |
]; |
||||||
|
|
||||||
const CREATED_AT = 'created_at'; |
const CREATED_AT = 'created_at'; |
||||||
const UPDATED_AT = 'updated_at'; |
const UPDATED_AT = 'updated_at'; |
||||||
|
|
||||||
const DEFAULT_TZ = 'Asia/Jakarta'; |
const DEFAULT_TZ = 'Asia/Jakarta'; |
||||||
const INSIDE = "INSIDE"; |
const INSIDE = "INSIDE"; |
||||||
const OUTSIDE = "OUTSIDE"; |
const OUTSIDE = "OUTSIDE"; |
||||||
const HOLIDAY = "HOLIDAY"; |
const HOLIDAY = "HOLIDAY"; |
||||||
|
|
||||||
/** |
/** |
||||||
* The attributes excluded from the model's JSON form. |
* The attributes excluded from the model's JSON form. |
||||||
* |
* |
||||||
* @var array |
* @var array |
||||||
*/ |
*/ |
||||||
protected $hidden = [ |
protected $hidden = [ |
||||||
'password', |
'password', |
||||||
]; |
]; |
||||||
|
|
||||||
/** |
/** |
||||||
* Get the identifier that will be stored in the subject claim of the JWT. |
* Get the identifier that will be stored in the subject claim of the JWT. |
||||||
* |
* |
||||||
* @return mixed |
* @return mixed |
||||||
*/ |
*/ |
||||||
public function getJWTIdentifier() |
public function getJWTIdentifier() |
||||||
{ |
{ |
||||||
return $this->getKey(); |
return $this->getKey(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Return a key value array, containing any custom claims to be added to the JWT. |
* Return a key value array, containing any custom claims to be added to the JWT. |
||||||
* |
* |
||||||
* @return array |
* @return array |
||||||
*/ |
*/ |
||||||
public function getJWTCustomClaims() |
public function getJWTCustomClaims() |
||||||
{ |
{ |
||||||
return []; |
return []; |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
* Get working hours for given timestamp |
* Get working hours for given timestamp |
||||||
* |
* |
||||||
* @return array of carbon or NULL in case HOLIDAY |
* @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( |
$workingTime = array( |
||||||
"from" => Carbon::createFromTimeString($f, $tz), |
"from" => Carbon::createFromTimeString($f, $tz), |
||||||
"to" => Carbon::createFromTimeString($t, $tz) |
"to" => Carbon::createFromTimeString($t, $tz) |
||||||
); |
); |
||||||
|
|
||||||
$userShift = UserShift::where('user_id',) |
$userShift = UserShift::where('user_id',) |
||||||
->orderByDesc('from_date') |
->orderByDesc('from_date') |
||||||
->first(); |
->first(); |
||||||
|
|
||||||
$shift = null; |
$shift = null; |
||||||
if ($userShift !== null) { |
if ($userShift !== null) { |
||||||
$shiftId = null; |
$shiftId = null; |
||||||
switch ($ts->shortEnglishDayOfWeek) { |
switch ($ts->shortEnglishDayOfWeek) { |
||||||
case "Mon": |
case "Mon": |
||||||
$shiftId = $userShift->mon_shift_id; |
$shiftId = $userShift->mon_shift_id; |
||||||
break; |
break; |
||||||
case "Tue": |
case "Tue": |
||||||
$shiftId = $userShift->tue_shift_id; |
$shiftId = $userShift->tue_shift_id; |
||||||
break; |
break; |
||||||
case "Wed": |
case "Wed": |
||||||
$shiftId = $userShift->wed_shift_id; |
$shiftId = $userShift->wed_shift_id; |
||||||
break; |
break; |
||||||
case "Thu": |
case "Thu": |
||||||
$shiftId = $userShift->thu_shift_id; |
$shiftId = $userShift->thu_shift_id; |
||||||
break; |
break; |
||||||
case "Fri": |
case "Fri": |
||||||
$shiftId = $userShift->fri_shift_id; |
$shiftId = $userShift->fri_shift_id; |
||||||
break; |
break; |
||||||
case "Sat": |
case "Sat": |
||||||
$shiftId = $userShift->sat_shift_id; |
$shiftId = $userShift->sat_shift_id; |
||||||
break; |
break; |
||||||
case "Sun": |
case "Sun": |
||||||
$shiftId = $userShift->sun_shift_id; |
$shiftId = $userShift->sun_shift_id; |
||||||
break; |
break; |
||||||
} |
} |
||||||
|
|
||||||
if ($shiftId === null) { |
if ($shiftId === null) { |
||||||
return null; |
return null; |
||||||
} |
} |
||||||
|
|
||||||
$shift = Shift::where('id', $shiftId)->first(); |
$shift = Shift::where('id', $shiftId)->first(); |
||||||
} else { |
} else { |
||||||
$shift = Shift::where('is_non_shift', true) |
$shift = Shift::where('is_non_shift', true) |
||||||
->orderByDesc('created_at') |
->orderByDesc('created_at') |
||||||
->first(); |
->first(); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
if ($shift !== null) { |
if ($shift !== null) { |
||||||
$from = Carbon::createFromTimeString($shift->start_time, $tz) |
$from = Carbon::createFromTimeString($shift->start_time, $tz) |
||||||
->subMinutes($shift->flex_time_minute); |
->subMinutes($shift->flex_time_minute); |
||||||
$to = Carbon::createFromTimeString($shift->end_time, $tz) |
$to = Carbon::createFromTimeString($shift->end_time, $tz) |
||||||
->addMinutes($shift->flex_time_minute); |
->addMinutes($shift->flex_time_minute); |
||||||
|
|
||||||
/* |
/* |
||||||
if ($to->lessThan($from)) |
if ($to->lessThan($from)) |
||||||
{ |
{ |
||||||
$to->addDay(); |
$to->addDay(); |
||||||
} |
} |
||||||
*/ |
*/ |
||||||
$workingTime['from'] = $from; |
$workingTime['from'] = $from; |
||||||
$workingTime['to'] = $to; |
$workingTime['to'] = $to; |
||||||
} |
} |
||||||
|
|
||||||
return $workingTime; |
return $workingTime; |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
* Get presence status |
* 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; |
$ts = $at; |
||||||
if ($at !== null) { |
if ($at !== null) { |
||||||
$ts = Carbon::now($tz); |
$ts = Carbon::now($tz); |
||||||
} |
} |
||||||
$tsSec = $ts->secondsSinceMidnight(); |
$tsSec = $ts->secondsSinceMidnight(); |
||||||
|
|
||||||
$status = ""; |
$status = ""; |
||||||
$wt = $this->getWorkingTime($ts, $tz); |
$wt = $this->getWorkingTime($ts, $tz); |
||||||
if ($wt === null) { |
if ($wt === null) { |
||||||
$status = self::HOLIDAY; |
$status = self::HOLIDAY; |
||||||
} else { |
} else { |
||||||
$from = $wt->from; |
$from = $wt->from; |
||||||
$to = $wt->to; |
$to = $wt->to; |
||||||
$tsFrom = $from->secondsSinceMidnight(); |
$tsFrom = $from->secondsSinceMidnight(); |
||||||
$tsTo = $to->secondsSinceMidnight(); |
$tsTo = $to->secondsSinceMidnight(); |
||||||
|
|
||||||
if ($from->greaterThan($to)) { |
if ($from->greaterThan($to)) { |
||||||
$tsMid = 24 * 60 * 60 - $tsFrom; |
$tsMid = 24 * 60 * 60 - $tsFrom; |
||||||
if ($tsSec >= $tsFrom || $tsSec < $tsTo) { |
if ($tsSec >= $tsFrom || $tsSec < $tsTo) { |
||||||
$status = self::INSIDE; |
$status = self::INSIDE; |
||||||
} else { |
} else { |
||||||
$status = self::OUTSIDE; |
$status = self::OUTSIDE; |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
if ($tsSec < $tsFrom || $tsSec > $tsTo) { |
if ($tsSec < $tsFrom || $tsSec > $tsTo) { |
||||||
$status = self::OUTSIDE; |
$status = self::OUTSIDE; |
||||||
} else { |
} else { |
||||||
$status = self::INSIDE; |
$status = self::INSIDE; |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
$clockIn = null; |
$clockIn = null; |
||||||
$clockOut = null; |
$clockOut = null; |
||||||
$inout = Presence::where('user_id', $this->id) |
$inout = Presence::where('user_id', $this->id) |
||||||
->orderByDesc('clock_in') |
->orderByDesc('clock_in') |
||||||
->first(); |
->first(); |
||||||
if ($inout !== null) { |
if ($inout !== null) { |
||||||
$clockIn = Carbon::parse($inout->clock_in, $tz); |
$clockIn = Carbon::parse($inout->clock_in, $tz); |
||||||
$clockOut = Carbon::parse($inout->clock_out, $tz); |
$clockOut = Carbon::parse($inout->clock_out, $tz); |
||||||
} |
} |
||||||
|
|
||||||
return array( |
return array( |
||||||
"status" => $status, |
"status" => $status, |
||||||
"ts" => $ts, |
"ts" => $ts, |
||||||
"clock_in" => $clockIn, |
"clock_in" => $clockIn, |
||||||
"clock_out" => $clockOut |
"clock_out" => $clockOut |
||||||
); |
); |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue