dstpabuaran.com/app/Models/Attendance.php
Yoga Pangestu 0023309a8f Refactor services to improve role checks and streamline data retrieval
- Updated CustomerService to simplify getAll method.
- Refactored ProductService to utilize HasRoleChecks trait and improved role verification logic.
- Enhanced ProductVariantService with new methods for fetching data for restocking and transactions.
- Cleaned up RawMaterialService by removing unused methods and improving data retrieval.
- Adjusted SupplierService to streamline getAll method.
- Refactored RoleService to use Spatie's Role model and improved role filtering logic.
- Updated NotificationService to handle role labels more effectively.
- Improved StockMutationService by removing redundant paginated method.
- Cleaned up various frontend components to directly accept necessary props instead of nested data objects.
- Updated tests to reflect changes in service method names and ensure proper notification handling.
2026-08-09 11:33:25 +07:00

66 lines
1.9 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Appends;
use Illuminate\Database\Eloquent\Attributes\Guarded;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
#[Appends(['formatted_attendance_date', 'formatted_check_in_at', 'formatted_check_out_at'])]
#[Guarded(['id'])]
class Attendance extends Model implements HasMedia
{
use HasFactory, InteractsWithMedia;
protected function casts(): array
{
return [
'attendance_date' => 'date:Y-m-d',
'check_in_at' => 'datetime',
'check_out_at' => 'datetime',
'check_in_latitude' => 'decimal:7',
'check_in_longitude' => 'decimal:7',
'check_out_latitude' => 'decimal:7',
'check_out_longitude' => 'decimal:7',
'work_duration_minutes' => 'integer',
];
}
protected function formattedAttendanceDate(): Attribute
{
return Attribute::make(
get: fn () => $this->attendance_date?->translatedFormat('l, d F Y'),
);
}
protected function formattedCheckInAt(): Attribute
{
return Attribute::make(
get: fn () => $this->check_in_at?->translatedFormat('l, d F Y H:i'),
);
}
protected function formattedCheckOutAt(): Attribute
{
return Attribute::make(
get: fn () => $this->check_out_at?->translatedFormat('l, d F Y H:i'),
);
}
public function employee(): BelongsTo
{
return $this->belongsTo(Employee::class);
}
public function payrollAdjustments(): HasMany
{
return $this->hasMany(PayrollAdjustment::class);
}
}