feat: setup Docker production stack, Vite asset compilation, and resolve audit findings (P1/P2)
This commit is contained in:
@@ -6,6 +6,7 @@ use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Employee extends Model
|
||||
@@ -13,6 +14,7 @@ class Employee extends Model
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'nik',
|
||||
'name',
|
||||
'unit_kerja',
|
||||
@@ -52,4 +54,14 @@ class Employee extends Model
|
||||
{
|
||||
return $this->hasMany(VehicleActivity::class, 'driver_id');
|
||||
}
|
||||
|
||||
public function p2hRecords(): HasMany
|
||||
{
|
||||
return $this->hasMany(P2hRecord::class, 'employee_id')->orderByDesc('inspected_at');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class P2hRecord extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'transaction_no',
|
||||
'vehicle_id',
|
||||
'employee_id',
|
||||
'template_id',
|
||||
'shift',
|
||||
'start_hm',
|
||||
'start_km',
|
||||
'start_time',
|
||||
'stop_time',
|
||||
'summary_condition',
|
||||
'defect_count',
|
||||
'general_notes',
|
||||
'validation_status',
|
||||
'validated_by',
|
||||
'validated_at',
|
||||
'validation_notes',
|
||||
'inspected_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'start_hm' => 'decimal:2',
|
||||
'start_km' => 'decimal:2',
|
||||
'defect_count' => 'integer',
|
||||
'start_time' => 'datetime',
|
||||
'stop_time' => 'datetime',
|
||||
'validated_at' => 'datetime',
|
||||
'inspected_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function vehicle(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Vehicle::class);
|
||||
}
|
||||
|
||||
public function employee(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Employee::class);
|
||||
}
|
||||
|
||||
public function template(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(P2hTemplate::class, 'template_id');
|
||||
}
|
||||
|
||||
public function validator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'validated_by');
|
||||
}
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(P2hRecordItem::class, 'p2h_record_id');
|
||||
}
|
||||
|
||||
public function isPending(): bool
|
||||
{
|
||||
return $this->validation_status === 'pending';
|
||||
}
|
||||
|
||||
public function isApproved(): bool
|
||||
{
|
||||
return $this->validation_status === 'approved';
|
||||
}
|
||||
|
||||
public function isRejected(): bool
|
||||
{
|
||||
return $this->validation_status === 'rejected';
|
||||
}
|
||||
|
||||
public function hasDefects(): bool
|
||||
{
|
||||
return $this->summary_condition === 'has_defect' || $this->defect_count > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class P2hRecordItem extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'p2h_record_id',
|
||||
'template_item_id',
|
||||
'section',
|
||||
'title',
|
||||
'question_type',
|
||||
'condition_status',
|
||||
'answer_value',
|
||||
'notes',
|
||||
];
|
||||
|
||||
public function record(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(P2hRecord::class, 'p2h_record_id');
|
||||
}
|
||||
|
||||
public function templateItem(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(P2hTemplateItem::class, 'template_item_id');
|
||||
}
|
||||
|
||||
public function isBaik(): bool
|
||||
{
|
||||
return strtolower((string)$this->condition_status) === 'baik';
|
||||
}
|
||||
|
||||
public function isRusak(): bool
|
||||
{
|
||||
return strtolower((string)$this->condition_status) === 'rusak';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class P2hTemplate extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'name',
|
||||
'file_name',
|
||||
'description',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(P2hTemplateItem::class, 'template_id')->orderBy('sequence');
|
||||
}
|
||||
|
||||
public function vehicles(): HasMany
|
||||
{
|
||||
return $this->hasMany(Vehicle::class, 'p2h_template_id');
|
||||
}
|
||||
|
||||
public function records(): HasMany
|
||||
{
|
||||
return $this->hasMany(P2hRecord::class, 'template_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ambil item yang dikelompokkan berdasarkan section.
|
||||
*/
|
||||
public function getGroupedItemsAttribute(): array
|
||||
{
|
||||
$grouped = [];
|
||||
foreach ($this->items as $item) {
|
||||
$grouped[$item->section][] = $item;
|
||||
}
|
||||
return $grouped;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class P2hTemplateItem extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'template_id',
|
||||
'section',
|
||||
'title',
|
||||
'question_type',
|
||||
'sequence',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'sequence' => 'integer',
|
||||
];
|
||||
|
||||
public function template(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(P2hTemplate::class, 'template_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Konversi question_type (termasuk nilai legacy) ke label standar resmi.
|
||||
*/
|
||||
public function getQuestionTypeLabelAttribute(): string
|
||||
{
|
||||
return match(strtolower(trim($this->question_type))) {
|
||||
'multiple lines text box', 'textarea' => 'Multiple Lines Text Box',
|
||||
'single line text box', 'text' => 'Single Line Text Box',
|
||||
'numerical value', 'number' => 'Numerical Value',
|
||||
'date' => 'Date',
|
||||
'datetime' => 'Datetime',
|
||||
'multiple choice: only one answer', 'choice', 'condition' => 'Multiple choice: only one answer',
|
||||
'multiple choice: multiple answers allowed', 'multiple_choice' => 'Multiple choice: multiple answers allowed',
|
||||
'matrix' => 'Matrix',
|
||||
default => $this->question_type,
|
||||
};
|
||||
}
|
||||
}
|
||||
+34
-1
@@ -52,6 +52,24 @@ class User extends Authenticatable
|
||||
];
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::deleting(function (User $user) {
|
||||
if ($user->employee) {
|
||||
if ($user->employee->activities()->exists() || $user->employee->p2hRecords()->exists()) {
|
||||
throw new \Exception("Tidak dapat menghapus user: Karyawan '{$user->name}' memiliki data audit riwayat operasional kendaraan atau inspeksi P2H.");
|
||||
}
|
||||
$user->employee->delete();
|
||||
}
|
||||
if ($user->securityGuard) {
|
||||
if ($user->securityGuard->activities()->exists()) {
|
||||
throw new \Exception("Tidak dapat menghapus user: Petugas Satpam '{$user->name}' memiliki riwayat data validasi pos gerbang.");
|
||||
}
|
||||
$user->securityGuard->delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function gate(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Gate::class);
|
||||
@@ -62,6 +80,16 @@ class User extends Authenticatable
|
||||
return $this->hasOne(SecurityGuard::class);
|
||||
}
|
||||
|
||||
public function employee(): HasOne
|
||||
{
|
||||
return $this->hasOne(Employee::class);
|
||||
}
|
||||
|
||||
public function isEmployee(): bool
|
||||
{
|
||||
return $this->role === 'employee';
|
||||
}
|
||||
|
||||
public function isGateOfficer(): bool
|
||||
{
|
||||
return $this->role === 'gate_officer';
|
||||
@@ -82,8 +110,13 @@ class User extends Authenticatable
|
||||
return $this->role === 'pg_admin';
|
||||
}
|
||||
|
||||
public function isSuperAdmin(): bool
|
||||
{
|
||||
return in_array($this->role, ['super_admin', 'superadmin']);
|
||||
}
|
||||
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
return $this->role === 'admin';
|
||||
return in_array($this->role, ['admin', 'super_admin', 'superadmin']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
@@ -15,8 +16,11 @@ class Vehicle extends Model
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'category',
|
||||
'parent_id',
|
||||
'p2h_template_id',
|
||||
'brand_type',
|
||||
'license_plate',
|
||||
'serial_number',
|
||||
'ownership',
|
||||
'division',
|
||||
'status',
|
||||
@@ -39,6 +43,7 @@ class Vehicle extends Model
|
||||
'current_km' => 'decimal:2',
|
||||
'fuel_consumption' => 'decimal:2',
|
||||
'production_year' => 'integer',
|
||||
'parent_id' => 'integer',
|
||||
];
|
||||
|
||||
public function isLightVehicle(): bool
|
||||
@@ -51,6 +56,16 @@ class Vehicle extends Model
|
||||
return $this->category === 'unit_support';
|
||||
}
|
||||
|
||||
public function isSupportCategory(): bool
|
||||
{
|
||||
return $this->isUnitSupport() && is_null($this->parent_id);
|
||||
}
|
||||
|
||||
public function isSupportUnit(): bool
|
||||
{
|
||||
return $this->isUnitSupport() && !is_null($this->parent_id);
|
||||
}
|
||||
|
||||
public function scopeLightVehicles(Builder $query): Builder
|
||||
{
|
||||
return $query->where('category', 'light_vehicle');
|
||||
@@ -61,11 +76,72 @@ class Vehicle extends Model
|
||||
return $query->where('category', 'unit_support');
|
||||
}
|
||||
|
||||
public function scopeUnitSupportCategories(Builder $query): Builder
|
||||
{
|
||||
return $query->where('category', 'unit_support')->whereNull('parent_id');
|
||||
}
|
||||
|
||||
public function scopeUnitSupportPhysical(Builder $query): Builder
|
||||
{
|
||||
return $query->where('category', 'unit_support')->whereNotNull('parent_id');
|
||||
}
|
||||
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Vehicle::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function units(): HasMany
|
||||
{
|
||||
return $this->hasMany(Vehicle::class, 'parent_id')->orderBy('code');
|
||||
}
|
||||
|
||||
/**
|
||||
* Hitung nomor urut 3 digit berikutnya untuk unit fisik kategori ini.
|
||||
*/
|
||||
public function getNextUnitNumber(): string
|
||||
{
|
||||
$existingCodes = $this->units()->pluck('code')->all();
|
||||
$maxNum = 0;
|
||||
foreach ($existingCodes as $c) {
|
||||
if (preg_match('/' . preg_quote($this->code, '/') . '-(\d+)$/i', $c, $matches)) {
|
||||
$num = (int)$matches[1];
|
||||
if ($num > $maxNum) {
|
||||
$maxNum = $num;
|
||||
}
|
||||
}
|
||||
}
|
||||
return str_pad((string)($maxNum + 1), 3, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hasilkan saran kode unit unik berikutnya (misal: BL01-001).
|
||||
*/
|
||||
public function getNextUnitCode(): string
|
||||
{
|
||||
return $this->code . '-' . $this->getNextUnitNumber();
|
||||
}
|
||||
|
||||
public function activities(): HasMany
|
||||
{
|
||||
return $this->hasMany(VehicleActivity::class);
|
||||
}
|
||||
|
||||
public function p2hTemplate(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(P2hTemplate::class, 'p2h_template_id');
|
||||
}
|
||||
|
||||
public function p2hRecords(): HasMany
|
||||
{
|
||||
return $this->hasMany(P2hRecord::class, 'vehicle_id')->orderByDesc('inspected_at');
|
||||
}
|
||||
|
||||
public function latestP2h(): HasOne
|
||||
{
|
||||
return $this->hasOne(P2hRecord::class, 'vehicle_id')->latestOfMany('inspected_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktivitas gerbang terakhir dari kendaraan ini.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user