feat(qma): implement unit support timesheet input, vehicle meter & location sync, and exports

This commit is contained in:
Ray1111-aa
2026-10-20 20:46:48 +07:00
parent fb67d7c63d
commit 0cd02a17cd
9 changed files with 2154 additions and 2 deletions
+5
View File
@@ -82,6 +82,11 @@ class Employee extends Model
return $this->hasMany(P2hRecord::class, 'employee_id')->orderByDesc('inspected_at');
}
public function supportTimesheets(): HasMany
{
return $this->hasMany(UnitSupportTimesheet::class, 'operator_id')->orderByDesc('date');
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
+82
View File
@@ -0,0 +1,82 @@
<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class UnitSupportTimesheet extends Model
{
use HasFactory;
protected $fillable = [
'timesheet_no',
'vehicle_id',
'operator_id',
'date',
'shift',
'meter_type',
'start_time',
'end_time',
'start_meter',
'end_meter',
'operating_hours',
'standby_hours',
'breakdown_hours',
'location',
'activity_type',
'task_description',
'fuel_liters',
'status',
'notes',
'created_by_user_id',
];
protected $casts = [
'date' => 'date',
'start_meter' => 'decimal:2',
'end_meter' => 'decimal:2',
'operating_hours' => 'decimal:2',
'standby_hours' => 'decimal:2',
'breakdown_hours' => 'decimal:2',
'fuel_liters' => 'decimal:2',
];
public function vehicle(): BelongsTo
{
return $this->belongsTo(Vehicle::class);
}
public function operator(): BelongsTo
{
return $this->belongsTo(Employee::class, 'operator_id');
}
public function createdByUser(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_user_id');
}
/**
* Generate nomor timesheet unik harian (Format: TS-US-YYYYMMDD-0001).
*/
public static function generateTimesheetNo(?Carbon $date = null): string
{
$d = $date ?: Carbon::today();
$dateStr = $d->format('Ymd');
$prefix = "TS-US-{$dateStr}-";
$last = self::where('timesheet_no', 'like', "{$prefix}%")
->orderByDesc('id')
->first();
$seq = 1;
if ($last && preg_match('/-(\d+)$/', $last->timesheet_no, $matches)) {
$seq = ((int) $matches[1]) + 1;
}
return $prefix . str_pad((string) $seq, 4, '0', STR_PAD_LEFT);
}
}
+10
View File
@@ -227,6 +227,16 @@ class Vehicle extends Model
return $this->hasOne(VehicleLocationHistory::class)->latestOfMany('recorded_at');
}
public function supportTimesheets(): HasMany
{
return $this->hasMany(UnitSupportTimesheet::class)->orderByDesc('date')->orderByDesc('id');
}
public function latestSupportTimesheet(): HasOne
{
return $this->hasOne(UnitSupportTimesheet::class)->latestOfMany('date');
}
/**
* Tentukan arah gerbang berikutnya yang sah:
* - 'ANY' jika belum pernah ada riwayat (kendaraan baru)