- Halaman baharu "Saluran Bermasalah": senarai semua saluran dalam DUN (dengan KTM & telefonnya), tanda/buang tanda bermasalah berserta catatan; admin DUN terhad ke DUN sendiri, superadmin semua DUN - Dashboard: baris saluran bermasalah diserlahkan kuning berserta lencana BERMASALAH dan catatan - No. telefon KTM kini ada butang "📞 Call" (tel:) dan "WhatsApp" (wa.me, dinormalkan ke format 60xxxxxxxxx) di dashboard dan halaman saluran bermasalah Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
107 lines
3.0 KiB
PHP
107 lines
3.0 KiB
PHP
<?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');
|
|
}
|
|
|
|
/**
|
|
* No. telefon dalam digit sahaja (untuk pautan tel:).
|
|
*/
|
|
public function telefonDigits(): ?string
|
|
{
|
|
$digit = preg_replace('/\D/', '', (string) $this->no_telefon);
|
|
|
|
return $digit !== '' ? $digit : null;
|
|
}
|
|
|
|
/**
|
|
* Pautan WhatsApp (wa.me) — normalkan ke format antarabangsa Malaysia.
|
|
*/
|
|
public function whatsappUrl(): ?string
|
|
{
|
|
$digit = $this->telefonDigits();
|
|
|
|
if ($digit === null) {
|
|
return null;
|
|
}
|
|
|
|
if (str_starts_with($digit, '0')) {
|
|
$digit = '6'.$digit;
|
|
} elseif (! str_starts_with($digit, '60')) {
|
|
$digit = '60'.$digit;
|
|
}
|
|
|
|
return 'https://wa.me/'.$digit;
|
|
}
|
|
|
|
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 ?? '-',
|
|
];
|
|
}
|
|
}
|