first commit
This commit is contained in:
37
app/Models/KehadiranTaklimat.php
Normal file
37
app/Models/KehadiranTaklimat.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Sppm\PetugasPermohonan;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class KehadiranTaklimat extends Model
|
||||
{
|
||||
protected $table = 'kehadiran_taklimat';
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'hadir_at' => 'datetime',
|
||||
'borang_diambil' => 'boolean',
|
||||
'borang_diambil_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function sesi(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(SesiTaklimat::class, 'sesi_taklimat_id');
|
||||
}
|
||||
|
||||
public function permohonan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PetugasPermohonan::class, 'permohonan_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Nombor siri berpad minimum 3 digit (001, 002, 1001).
|
||||
*/
|
||||
public function getNomborSiriPaparAttribute(): string
|
||||
{
|
||||
return str_pad((string) $this->nombor_siri, 3, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
37
app/Models/SesiTaklimat.php
Normal file
37
app/Models/SesiTaklimat.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Sppm\Dun;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SesiTaklimat extends Model
|
||||
{
|
||||
protected $table = 'sesi_taklimat';
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'tarikh' => 'date',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (SesiTaklimat $sesi) {
|
||||
$sesi->qr_token ??= Str::random(32);
|
||||
});
|
||||
}
|
||||
|
||||
public function dun(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Dun::class, 'dun_id');
|
||||
}
|
||||
|
||||
public function kehadiran(): HasMany
|
||||
{
|
||||
return $this->hasMany(KehadiranTaklimat::class, 'sesi_taklimat_id');
|
||||
}
|
||||
}
|
||||
12
app/Models/Sppm/Dun.php
Normal file
12
app/Models/Sppm/Dun.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Sppm;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Dun extends Model
|
||||
{
|
||||
protected $connection = 'sppm';
|
||||
protected $table = 'dun';
|
||||
protected $guarded = [];
|
||||
}
|
||||
12
app/Models/Sppm/JawatanTetapan.php
Normal file
12
app/Models/Sppm/JawatanTetapan.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Sppm;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class JawatanTetapan extends Model
|
||||
{
|
||||
protected $connection = 'sppm';
|
||||
protected $table = 'jawatan_tetapan';
|
||||
protected $guarded = [];
|
||||
}
|
||||
28
app/Models/Sppm/PetugasAssignment.php
Normal file
28
app/Models/Sppm/PetugasAssignment.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Sppm;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PetugasAssignment extends Model
|
||||
{
|
||||
protected $connection = 'sppm';
|
||||
protected $table = 'petugas_assignments';
|
||||
protected $guarded = [];
|
||||
|
||||
public function pusatMengundi(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PusatMengundi::class, 'pusat_mengundi_id');
|
||||
}
|
||||
|
||||
public function saluran(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Saluran::class, 'saluran_id');
|
||||
}
|
||||
|
||||
public function jawatan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(JawatanTetapan::class, 'jawatan_tetapan_id');
|
||||
}
|
||||
}
|
||||
76
app/Models/Sppm/PetugasPermohonan.php
Normal file
76
app/Models/Sppm/PetugasPermohonan.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Sppm;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class PetugasPermohonan extends Model
|
||||
{
|
||||
protected $connection = 'sppm';
|
||||
protected $table = 'petugas_permohonan';
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* Petugas berstatus 'assigned' untuk sesuatu DUN. Padanan DUN melalui
|
||||
* dun_id permohonan atau dun pusat mengundi penempatan.
|
||||
*/
|
||||
public function scopeAssignedUntukDun($query, int $dunId)
|
||||
{
|
||||
return $query->where('status', 'assigned')
|
||||
->where(function ($q) use ($dunId) {
|
||||
$q->where('dun_id', $dunId)
|
||||
->orWhereHas('assignments.pusatMengundi', fn ($qq) => $qq->where('dun_id', $dunId));
|
||||
});
|
||||
}
|
||||
|
||||
public function dun(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Dun::class, 'dun_id');
|
||||
}
|
||||
|
||||
public function assignments(): HasMany
|
||||
{
|
||||
return $this->hasMany(PetugasAssignment::class, 'permohonan_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Penempatan utama petugas (urutan terendah).
|
||||
*/
|
||||
public function assignmentUtama(): ?PetugasAssignment
|
||||
{
|
||||
if ($this->relationLoaded('assignments')) {
|
||||
return $this->assignments->sortBy('urutan')->first();
|
||||
}
|
||||
|
||||
return $this->assignments()
|
||||
->with(['pusatMengundi', 'saluran', 'jawatan'])
|
||||
->orderBy('urutan')
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Maklumat penempatan untuk paparan: pusat mengundi, saluran, jawatan.
|
||||
* Diambil daripada petugas_assignments; fallback kepada medan permohonan.
|
||||
*/
|
||||
public function butiranPenempatan(): array
|
||||
{
|
||||
$assignment = $this->assignmentUtama();
|
||||
|
||||
$pusatMengundi = $assignment?->pusatMengundi
|
||||
?? ($this->pusat_mengundi_id ? PusatMengundi::find($this->pusat_mengundi_id) : null);
|
||||
|
||||
$saluran = $assignment?->saluran
|
||||
?? ($this->assigned_saluran_id ? Saluran::find($this->assigned_saluran_id) : null);
|
||||
|
||||
$jawatan = $assignment?->jawatan
|
||||
?? ($this->jawatan_id ? JawatanTetapan::find($this->jawatan_id) : null);
|
||||
|
||||
return [
|
||||
'pusat_mengundi' => $pusatMengundi?->nama ?? '-',
|
||||
'saluran' => $saluran ? 'Saluran ' . $saluran->nombor_saluran : '-',
|
||||
'jawatan' => $jawatan?->nama ?? '-',
|
||||
];
|
||||
}
|
||||
}
|
||||
12
app/Models/Sppm/PusatMengundi.php
Normal file
12
app/Models/Sppm/PusatMengundi.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Sppm;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PusatMengundi extends Model
|
||||
{
|
||||
protected $connection = 'sppm';
|
||||
protected $table = 'pusat_mengundi';
|
||||
protected $guarded = [];
|
||||
}
|
||||
12
app/Models/Sppm/Saluran.php
Normal file
12
app/Models/Sppm/Saluran.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Sppm;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Saluran extends Model
|
||||
{
|
||||
protected $connection = 'sppm';
|
||||
protected $table = 'saluran';
|
||||
protected $guarded = [];
|
||||
}
|
||||
42
app/Models/User.php
Normal file
42
app/Models/User.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
#[Fillable(['name', 'email', 'password', 'role', 'dun_id'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
return $this->role === 'admin';
|
||||
}
|
||||
|
||||
public function isPengurus(): bool
|
||||
{
|
||||
return $this->role === 'pengurus';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user