Files
sam-manage/app/Models/VehicleLog.php
김보곤 35d0260732 feat:차량일지 구분 유형 확장 및 라벨 수정
- 구분 유형 추가: 출퇴근용(왕복), 업무용(왕복), 비업무용(왕복)
- 비업무 라벨을 '비업무용(개인)'으로 변경
- 출발지/도착지 장소명 라벨 수정 (장소명 → 출발지명/도착지명)
- 새 유형별 색상 추가

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-03 13:27:56 +09:00

93 lines
2.7 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class VehicleLog extends Model
{
use SoftDeletes;
protected $fillable = [
'tenant_id',
'vehicle_id',
'log_date',
'department',
'driver_name',
'trip_type',
'departure_type',
'departure_name',
'departure_address',
'arrival_type',
'arrival_name',
'arrival_address',
'distance_km',
'note',
];
protected $casts = [
'log_date' => 'date:Y-m-d',
'distance_km' => 'integer',
];
// trip_type 상수
public const TRIP_TYPE_COMMUTE_TO = 'commute_to';
public const TRIP_TYPE_COMMUTE_FROM = 'commute_from';
public const TRIP_TYPE_BUSINESS = 'business';
public const TRIP_TYPE_PERSONAL = 'personal';
public const TRIP_TYPE_COMMUTE_ROUND = 'commute_round';
public const TRIP_TYPE_BUSINESS_ROUND = 'business_round';
public const TRIP_TYPE_PERSONAL_ROUND = 'personal_round';
// location_type 상수
public const LOCATION_TYPE_HOME = 'home';
public const LOCATION_TYPE_OFFICE = 'office';
public const LOCATION_TYPE_CLIENT = 'client';
public const LOCATION_TYPE_OTHER = 'other';
public static function tripTypeLabels(): array
{
return [
self::TRIP_TYPE_COMMUTE_TO => '출근용',
self::TRIP_TYPE_COMMUTE_FROM => '퇴근용',
self::TRIP_TYPE_BUSINESS => '업무용',
self::TRIP_TYPE_PERSONAL => '비업무용(개인)',
self::TRIP_TYPE_COMMUTE_ROUND => '출퇴근용(왕복)',
self::TRIP_TYPE_BUSINESS_ROUND => '업무용(왕복)',
self::TRIP_TYPE_PERSONAL_ROUND => '비업무용(왕복)',
];
}
public static function locationTypeLabels(): array
{
return [
self::LOCATION_TYPE_HOME => '자택',
self::LOCATION_TYPE_OFFICE => '회사',
self::LOCATION_TYPE_CLIENT => '거래처',
self::LOCATION_TYPE_OTHER => '기타',
];
}
public function vehicle(): BelongsTo
{
return $this->belongsTo(CorporateVehicle::class, 'vehicle_id');
}
public function getTripTypeLabelAttribute(): string
{
return self::tripTypeLabels()[$this->trip_type] ?? $this->trip_type;
}
public function getDepartureTypeLabelAttribute(): string
{
return self::locationTypeLabels()[$this->departure_type] ?? ($this->departure_type ?? '');
}
public function getArrivalTypeLabelAttribute(): string
{
return self::locationTypeLabels()[$this->arrival_type] ?? ($this->arrival_type ?? '');
}
}