bug fixes, daily reports, holidays
This commit is contained in:
17
app/Models/DailyReport.php
Normal file
17
app/Models/DailyReport.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DailyReport extends Model
|
||||
{
|
||||
protected $fillable = ['user_id', 'report_date', 'content'];
|
||||
protected $casts = [
|
||||
'report_date' => 'date',
|
||||
];
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(StaffMember::class);
|
||||
}
|
||||
}
|
||||
@@ -29,4 +29,21 @@ class OfficeLocation extends Model
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
20
app/Models/PublicHoliday.php
Normal file
20
app/Models/PublicHoliday.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PublicHoliday extends Model
|
||||
{
|
||||
protected $fillable = ['office_location_id', 'name', 'holiday_date', 'is_recurring'];
|
||||
// protected $guarded = ['id']
|
||||
protected $casts = [
|
||||
'holiday_date' => 'date',
|
||||
'is_recurring' => 'boolean',
|
||||
];
|
||||
|
||||
public function location()
|
||||
{
|
||||
return $this->belongsTo(OfficeLocation::class, 'office_location_id');
|
||||
}
|
||||
}
|
||||
10
app/Models/ReportOverride.php
Normal file
10
app/Models/ReportOverride.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ReportOverride extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
}
|
||||
@@ -27,7 +27,13 @@ class StaffMember extends Authenticatable
|
||||
public function dependents() {
|
||||
return $this->hasMany(StaffDependent::class, 'staff_id');
|
||||
}
|
||||
public function dailyReports() {
|
||||
return $this->hasMany(DailyReport::class, 'user_id');
|
||||
}
|
||||
|
||||
public function department(){
|
||||
return $this->hasOne('App\Models\Department', 'id', 'department_id');
|
||||
}
|
||||
// 4. Cast dates correctly
|
||||
protected $casts = [
|
||||
// 'dob' => 'date',
|
||||
|
||||
Reference in New Issue
Block a user