50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class OfficeLocation extends Model
|
|
{
|
|
protected $guarded = array('id');
|
|
protected $table = 'office_locations';
|
|
|
|
public function created_by_info(){
|
|
return $this->hasOne('App\Models\StaffMember', 'id', 'user_id');
|
|
}
|
|
public function country_manager_info(){
|
|
// return $this->hasOne('App\Models\StaffMember', 'id', 'country_manager_id');
|
|
return $this->hasOne('App\Models\StaffMember', 'id', 'country_manager_id');
|
|
}
|
|
|
|
|
|
|
|
public function manager()
|
|
{
|
|
return $this->belongsTo(StaffMember::class, 'country_manager_id');
|
|
}
|
|
|
|
|
|
public function documents()
|
|
{
|
|
return $this->hasMany(OfficeLocationDocument::class, 'office_location_id');
|
|
}
|
|
public function holidays()
|
|
{
|
|
return $this->hasMany(PublicHoliday::class)->orderBy('holiday_date');
|
|
}
|
|
public function isHoliday($date)
|
|
{
|
|
$parsedDate = \Carbon\Carbon::parse($date);
|
|
|
|
return $this->holidays()->where(function($query) use ($parsedDate) {
|
|
$query->whereDate('holiday_date', $parsedDate->format('Y-m-d'))
|
|
->orWhere(function($q) use ($parsedDate) {
|
|
$q->where('is_recurring', true)
|
|
->whereMonth('holiday_date', $parsedDate->month)
|
|
->whereDay('holiday_date', $parsedDate->day);
|
|
});
|
|
})->exists();
|
|
}
|
|
}
|