This commit is contained in:
Saufi
2026-06-03 08:51:22 +08:00
commit a14d43fe34
347 changed files with 38197 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Http\Requests\Admin\Management;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class AssignApplicationRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
protected function prepareForValidation(): void
{
$this->merge([
'saluran_mengundi_id' => blank($this->input('saluran_mengundi_id')) ? null : $this->input('saluran_mengundi_id'),
'reports_to_assignment_id' => blank($this->input('reports_to_assignment_id')) ? null : $this->input('reports_to_assignment_id'),
]);
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'position_id' => ['required', 'integer', 'exists:positions,id'],
'pusat_mengundi_id' => ['required', 'integer', 'exists:pusat_mengundis,id'],
'saluran_mengundi_id' => ['nullable', 'integer', 'exists:saluran_mengundis,id'],
'reports_to_assignment_id' => ['nullable', 'integer', 'exists:staff_assignments,id'],
'status' => ['nullable', Rule::in(['active', 'inactive', 'replaced', 'cancelled'])],
'note' => ['nullable', 'string', 'max:2000'],
];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Requests\Admin\Management;
use Illuminate\Foundation\Http\FormRequest;
class DeleteRepresentativeRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'note' => ['nullable', 'string', 'max:2000'],
];
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Http\Requests\Admin\Management;
use Illuminate\Foundation\Http\FormRequest;
class StoreManualApplicationRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
protected function prepareForValidation(): void
{
$this->merge([
'ic_number' => preg_replace('/\D+/', '', (string) $this->input('ic_number')),
'phone_number' => trim((string) $this->input('phone_number')),
'email' => blank($this->input('email')) ? null : strtolower(trim((string) $this->input('email'))),
'selected_ktm_assignment_id' => blank($this->input('selected_ktm_assignment_id')) ? null : $this->input('selected_ktm_assignment_id'),
'bank_name' => blank($this->input('bank_name')) ? null : trim((string) $this->input('bank_name')),
'bank_account_number' => blank($this->input('bank_account_number')) ? null : preg_replace('/\D+/', '', (string) $this->input('bank_account_number')),
]);
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'election_id' => ['required', 'integer', 'exists:elections,id'],
'pusat_mengundi_id' => ['required', 'integer', 'exists:pusat_mengundis,id'],
'selected_ktm_assignment_id' => ['nullable', 'integer', 'exists:staff_assignments,id'],
'requested_position_id' => ['required', 'integer', 'exists:positions,id'],
'name' => ['required', 'string', 'max:255'],
'ic_number' => ['required', 'digits:12'],
'phone_number' => ['required', 'string', 'max:30'],
'email' => ['nullable', 'email', 'max:255'],
'address' => ['nullable', 'string', 'max:2000'],
'bank_name' => ['nullable', 'string', 'max:255'],
'bank_account_number' => ['nullable', 'string', 'max:50'],
'note' => ['nullable', 'string', 'max:2000'],
];
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Http\Requests\Admin\Management;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreRepresentativeRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
protected function prepareForValidation(): void
{
$this->merge([
'ic_number' => blank($this->input('ic_number')) ? null : preg_replace('/\D+/', '', (string) $this->input('ic_number')),
'saluran_mengundi_id' => blank($this->input('saluran_mengundi_id')) ? null : $this->input('saluran_mengundi_id'),
]);
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'type' => ['required', Rule::in(['police', 'kkm', 'jkm'])],
'election_id' => ['required', 'integer', 'exists:elections,id'],
'pusat_mengundi_id' => ['required', 'integer', 'exists:pusat_mengundis,id'],
'saluran_mengundi_id' => ['nullable', 'integer', 'exists:saluran_mengundis,id'],
'name' => ['required', 'string', 'max:255'],
'ic_number' => ['nullable', 'digits:12'],
'phone_number' => ['nullable', 'string', 'max:30'],
'rank' => ['nullable', 'string', 'max:255'],
'station' => ['nullable', 'string', 'max:255'],
'agency' => ['nullable', 'string', 'max:255'],
'notes' => ['nullable', 'string', 'max:2000'],
'note' => ['nullable', 'string', 'max:2000'],
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Requests\Admin\Management;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreReturnTransactionRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'quantity' => ['required', 'integer', 'min:1', 'max:9999'],
'returned_at' => ['nullable', 'date'],
'returned_by_name' => ['required', 'string', 'max:255'],
'return_condition' => ['required', Rule::in(['baik', 'rosak'])],
'notes' => ['nullable', 'string', 'max:2000'],
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Requests\Admin\Management;
use Illuminate\Foundation\Http\FormRequest;
class StoreTakenTransactionRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'quantity' => ['required', 'integer', 'min:1', 'max:9999'],
'taken_at' => ['nullable', 'date'],
'taken_by_name' => ['required', 'string', 'max:255'],
'notes' => ['nullable', 'string', 'max:2000'],
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests\Admin\Management;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreWheelchairTransactionRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'transaction_type' => ['required', Rule::in(['taken', 'returned'])],
'quantity' => ['required', 'integer', 'min:1', 'max:9999'],
'taken_at' => ['nullable', 'date'],
'taken_by_name' => ['nullable', 'string', 'max:255', 'required_if:transaction_type,taken'],
'returned_at' => ['nullable', 'date'],
'return_condition' => ['nullable', Rule::in(['baik', 'rosak']), 'required_if:transaction_type,returned'],
'notes' => ['nullable', 'string', 'max:2000'],
];
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Http\Requests\Admin\Management;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateManagedApplicationRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
protected function prepareForValidation(): void
{
$this->merge([
'ic_number' => preg_replace('/\D+/', '', (string) $this->input('ic_number')),
'phone_number' => trim((string) $this->input('phone_number')),
'email' => blank($this->input('email')) ? null : strtolower(trim((string) $this->input('email'))),
'selected_ktm_assignment_id' => blank($this->input('selected_ktm_assignment_id')) ? null : $this->input('selected_ktm_assignment_id'),
'approved_position_id' => blank($this->input('approved_position_id')) ? null : $this->input('approved_position_id'),
'bank_name' => blank($this->input('bank_name')) ? null : trim((string) $this->input('bank_name')),
'bank_account_number' => blank($this->input('bank_account_number')) ? null : preg_replace('/\D+/', '', (string) $this->input('bank_account_number')),
]);
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'pusat_mengundi_id' => ['required', 'integer', 'exists:pusat_mengundis,id'],
'selected_ktm_assignment_id' => ['nullable', 'integer', 'exists:staff_assignments,id'],
'requested_position_id' => ['required', 'integer', 'exists:positions,id'],
'approved_position_id' => ['nullable', 'integer', 'exists:positions,id'],
'status' => ['required', Rule::in(['draft', 'submitted', 'under_ppm_review', 'approved', 'rejected', 'assigned', 'cancelled'])],
'name' => ['required', 'string', 'max:255'],
'ic_number' => ['required', 'digits:12'],
'phone_number' => ['required', 'string', 'max:30'],
'email' => ['nullable', 'email', 'max:255'],
'address' => ['nullable', 'string', 'max:2000'],
'bank_name' => ['nullable', 'string', 'max:255'],
'bank_account_number' => ['nullable', 'string', 'max:50'],
'note' => ['nullable', 'string', 'max:2000'],
];
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Http\Requests\Admin\Management;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateStaffAssignmentRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
protected function prepareForValidation(): void
{
$this->merge([
'saluran_mengundi_id' => blank($this->input('saluran_mengundi_id')) ? null : $this->input('saluran_mengundi_id'),
'reports_to_assignment_id' => blank($this->input('reports_to_assignment_id')) ? null : $this->input('reports_to_assignment_id'),
]);
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'position_id' => ['required', 'integer', 'exists:positions,id'],
'pusat_mengundi_id' => ['required', 'integer', 'exists:pusat_mengundis,id'],
'saluran_mengundi_id' => ['nullable', 'integer', 'exists:saluran_mengundis,id'],
'reports_to_assignment_id' => ['nullable', 'integer', 'exists:staff_assignments,id'],
'status' => ['required', Rule::in(['active', 'inactive', 'replaced', 'cancelled'])],
'note' => ['nullable', 'string', 'max:2000'],
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Requests\Admin\Management;
use Illuminate\Foundation\Http\FormRequest;
class UpsertWheelchairAllocationRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'election_id' => ['required', 'integer', 'exists:elections,id'],
'pusat_mengundi_id' => ['required', 'integer', 'exists:pusat_mengundis,id'],
'allocated_quantity' => ['required', 'integer', 'min:0', 'max:9999'],
'notes' => ['nullable', 'string', 'max:2000'],
];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Requests\Admin\Setup;
use Illuminate\Foundation\Http\FormRequest;
class AssignPpmRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'user_id' => ['required', 'exists:users,id'],
];
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Http\Requests\Admin\Setup;
use Illuminate\Foundation\Http\FormRequest;
class ImportPusatRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'election_id' => ['required', 'integer', 'exists:elections,id'],
'dun_code' => ['required', 'string', 'max:20'],
'dun_name' => ['required', 'string', 'max:255'],
'file' => ['required', 'file', 'mimes:xlsx', 'max:10240'],
];
}
/**
* @return array<string, string>
*/
public function attributes(): array
{
return [
'election_id' => 'pilihan raya',
'dun_code' => 'kod DUN',
'dun_name' => 'nama DUN',
'file' => 'fail XLSX',
];
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Http\Requests\Admin\Setup;
use App\Models\BahagianPilihanraya;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpsertBahagianPilihanrayaRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
$bahagian = $this->route('bahagianPilihanraya');
return [
'election_id' => ['required', 'exists:elections,id'],
'code' => [
'required',
'string',
'max:50',
Rule::unique('bahagian_pilihanrayas', 'code')
->where('election_id', $this->input('election_id'))
->ignore($bahagian instanceof BahagianPilihanraya ? $bahagian->id : null),
],
'name' => ['required', 'string', 'max:255'],
];
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Http\Requests\Admin\Setup;
use App\Models\DaerahMengundi;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpsertDaerahMengundiRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
$daerah = $this->route('daerahMengundi');
return [
'election_id' => ['required', 'exists:elections,id'],
'bahagian_pilihanraya_id' => ['required', 'exists:bahagian_pilihanrayas,id'],
'code' => [
'required',
'string',
'max:50',
Rule::unique('daerah_mengundis', 'code')
->where('election_id', $this->input('election_id'))
->ignore($daerah instanceof DaerahMengundi ? $daerah->id : null),
],
'name' => ['required', 'string', 'max:255'],
];
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Http\Requests\Admin\Setup;
use Illuminate\Foundation\Http\FormRequest;
class UpsertElectionSettingsRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'registration_start_date' => ['required', 'date'],
'registration_end_date' => ['required', 'date', 'after_or_equal:registration_start_date'],
'polling_date' => ['required', 'date', 'after_or_equal:registration_end_date'],
'is_attendance_active' => ['required', 'boolean'],
'is_registration_open_override' => ['nullable', 'in:,0,1'],
];
}
protected function prepareForValidation(): void
{
$this->merge([
'is_attendance_active' => $this->boolean('is_attendance_active'),
'is_registration_open_override' => $this->resolveOverride(),
]);
}
private function resolveOverride(): ?bool
{
$value = $this->input('is_registration_open_override');
if ($value === '' || $value === null) {
return null;
}
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Requests\Admin\Setup;
use Illuminate\Foundation\Http\FormRequest;
class UpsertPositionQuotaRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'position_id' => ['required', 'exists:positions,id'],
'quota' => ['required', 'integer', 'min:0', 'max:9999'],
];
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Http\Requests\Admin\Setup;
use App\Models\Position;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpsertPositionRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
$position = $this->route('position');
return [
'code' => [
'required',
'string',
'max:50',
Rule::unique('positions', 'code')->ignore($position instanceof Position ? $position->id : null),
],
'name' => ['required', 'string', 'max:255'],
'scope' => ['required', Rule::in(['pusat', 'saluran', 'external'])],
'is_public_applyable' => ['nullable', 'boolean'],
'is_assignable' => ['nullable', 'boolean'],
'allows_dual_role' => ['nullable', 'boolean'],
'sort_order' => ['nullable', 'integer', 'min:0', 'max:999'],
];
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Http\Requests\Admin\Setup;
use App\Models\PusatMengundi;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpsertPusatMengundiRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
$pusatMengundi = $this->route('pusatMengundi');
$pusatId = $pusatMengundi instanceof PusatMengundi ? $pusatMengundi->id : null;
$operationalQuantity = $this->isMethod('post') ? ['required', 'integer'] : ['sometimes', 'integer'];
return [
'election_id' => ['required', 'integer', 'exists:elections,id'],
'dun_id' => ['nullable', 'integer', 'exists:duns,id'],
'code' => [
'required',
'string',
'max:50',
Rule::unique('pusat_mengundis', 'code')
->where(fn ($query) => $query->where('election_id', $this->input('election_id')))
->ignore($pusatId),
],
'name' => ['required', 'string', 'max:255'],
'address' => ['nullable', 'string', 'max:2000'],
'saluran_count' => [...$operationalQuantity, 'min:1', 'max:100'],
'ktm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
'polis_iring_count' => [...$operationalQuantity, 'min:0', 'max:100'],
'kp_count' => [...$operationalQuantity, 'min:0', 'max:100'],
'ppm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
'kpdp_count' => [...$operationalQuantity, 'min:0', 'max:100'],
'papm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
'jkm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
'kkm_count' => [...$operationalQuantity, 'min:0', 'max:100'],
'calon_tambahan_count' => [...$operationalQuantity, 'min:0', 'max:100'],
];
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Http\Requests\Admin\Setup;
use App\Models\PusatMengundi;
use App\Models\SaluranMengundi;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpsertSaluranMengundiRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('Admin') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
$pusatMengundi = $this->route('pusatMengundi');
$pusatId = $pusatMengundi instanceof PusatMengundi ? $pusatMengundi->id : null;
$saluranMengundi = $this->route('saluranMengundi');
$saluranId = $saluranMengundi instanceof SaluranMengundi ? $saluranMengundi->id : null;
return [
'number' => [
'required',
'string',
'max:20',
Rule::unique('saluran_mengundis', 'number')
->where(fn ($query) => $query->where('pusat_mengundi_id', $pusatId))
->ignore($saluranId),
],
'voter_count' => ['nullable', 'integer', 'min:0'],
];
}
}

View File

@@ -0,0 +1,86 @@
<?php
namespace App\Http\Requests\Auth;
use Illuminate\Auth\Events\Lockout;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
class LoginRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'email' => ['required', 'string', 'email'],
'password' => ['required', 'string'],
];
}
/**
* Attempt to authenticate the request's credentials.
*
* @throws ValidationException
*/
public function authenticate(): void
{
$this->ensureIsNotRateLimited();
if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
RateLimiter::hit($this->throttleKey());
throw ValidationException::withMessages([
'email' => trans('auth.failed'),
]);
}
RateLimiter::clear($this->throttleKey());
}
/**
* Ensure the login request is not rate limited.
*
* @throws ValidationException
*/
public function ensureIsNotRateLimited(): void
{
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
return;
}
event(new Lockout($this));
$seconds = RateLimiter::availableIn($this->throttleKey());
throw ValidationException::withMessages([
'email' => trans('auth.throttle', [
'seconds' => $seconds,
'minutes' => ceil($seconds / 60),
]),
]);
}
/**
* Get the rate limiting throttle key for the request.
*/
public function throttleKey(): string
{
return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip());
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Http\Requests\Kewangan;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateBankVerificationRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasAnyRole(['Admin Kewangan', 'Admin']) === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'status' => ['required', Rule::in(['pending', 'verified', 'rejected', 'requires_correction'])],
'finance_note' => ['nullable', 'string', 'max:2000'],
];
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Http\Requests\Ktm;
use Illuminate\Foundation\Http\FormRequest;
class RegisterKpApplicantRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('KTM') === true;
}
protected function prepareForValidation(): void
{
$this->merge([
'ic_number' => preg_replace('/\D+/', '', (string) $this->input('ic_number')),
'phone_number' => trim((string) $this->input('phone_number')),
]);
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'ktm_assignment_id' => ['required', 'integer', 'exists:staff_assignments,id'],
'name' => ['required', 'string', 'max:255'],
'ic_number' => ['required', 'digits:12'],
'phone_number' => ['required', 'string', 'max:30'],
'email' => ['required', 'email', 'max:255'],
'address' => ['nullable', 'string', 'max:1000'],
];
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Http\Requests\Ppm;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class ApproveApplicationRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('PPM') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'approved_position_code' => ['required', Rule::in(['KTM', 'KP', 'KPDP', 'PAPM'])],
'saluran_mengundi_id' => [
Rule::requiredIf(fn (): bool => $this->input('approved_position_code') === 'KTM'),
'nullable',
'integer',
],
'ktm_assignment_id' => [
Rule::requiredIf(fn (): bool => in_array($this->input('approved_position_code'), ['KP', 'KPDP'], true)),
'nullable',
'integer',
],
'note' => ['nullable', 'string', 'max:1000'],
];
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Requests\Ppm;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class RecordAttendanceRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('PPM') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'attendance' => ['required', 'array'],
'attendance.*.status' => ['required', Rule::in(['present', 'absent', 'not_recorded'])],
'attendance.*.check_in_time' => ['nullable', 'date'],
'attendance.*.note' => ['nullable', 'string', 'max:1000'],
];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Requests\Ppm;
use Illuminate\Foundation\Http\FormRequest;
class RejectApplicationRequest extends FormRequest
{
public function authorize(): bool
{
return $this->user()?->hasRole('PPM') === true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'reason' => ['required', 'string', 'max:1000'],
];
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Requests;
use App\Models\User;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class ProfileUpdateRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
'email' => [
'required',
'string',
'lowercase',
'email',
'max:255',
Rule::unique(User::class)->ignore($this->user()->id),
],
];
}
}

View File

@@ -0,0 +1,158 @@
<?php
namespace App\Http\Requests\Public;
use App\Models\Application;
use App\Models\Election;
use App\Models\Position;
use App\Models\PusatMengundi;
use App\Services\Public\KtmVacancyService;
use App\Services\RegistrationPeriodService;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Validator;
class StorePublicApplicationRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
protected function prepareForValidation(): void
{
$this->merge([
'ic_number' => preg_replace('/\D+/', '', (string) $this->input('ic_number')),
'phone_number' => trim((string) $this->input('phone_number')),
'bank_account_number' => preg_replace('/[\s-]+/', '', (string) $this->input('bank_account_number')),
]);
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
'ic_number' => ['required', 'digits:12'],
'phone_number' => ['required', 'string', 'max:30'],
'email' => ['nullable', 'email', 'max:255'],
'address' => ['required', 'string', 'max:1000'],
'requested_position_code' => ['required', Rule::in(['KTM', 'KP', 'KPDP', 'PAPM'])],
'selected_ktm_assignment_id' => [
Rule::requiredIf(fn (): bool => in_array($this->input('requested_position_code'), ['KP', 'KPDP'], true)),
'nullable',
'integer',
],
'bank_name' => ['required', 'string', 'max:255'],
'bank_account_number' => ['required', 'string', 'max:50'],
'ic_document' => ['required', 'file', 'mimes:pdf,jpg,jpeg,png', 'max:5120'],
'bank_statement' => ['required', 'file', 'mimes:pdf,jpg,jpeg,png', 'max:5120'],
];
}
public function after(): array
{
return [
function (Validator $validator): void {
$pusatMengundi = $this->route('pusatMengundi');
if (! $pusatMengundi instanceof PusatMengundi) {
return;
}
/** @var Election $election */
$election = $pusatMengundi->election()->with('settings')->firstOrFail();
if (! app(RegistrationPeriodService::class)->isOpen($election)) {
$validator->errors()->add('registration', app(RegistrationPeriodService::class)->closedMessage($election));
}
$roleCode = (string) $this->input('requested_position_code');
$position = Position::query()
->where('code', $roleCode)
->where('is_public_applyable', true)
->first();
if (! $position instanceof Position) {
$validator->errors()->add('requested_position_code', 'Jawatan yang dipilih tidak dibuka untuk permohonan awam.');
return;
}
$this->validateDuplicateIc($validator, $pusatMengundi);
if (in_array($roleCode, ['KP', 'KPDP'], true)) {
$this->validateKtmVacancy($validator, $pusatMengundi, $roleCode);
}
},
];
}
/**
* @return array<string, string>
*/
public function attributes(): array
{
return [
'name' => 'nama',
'ic_number' => 'no. kad pengenalan',
'phone_number' => 'no. telefon',
'email' => 'emel',
'address' => 'alamat',
'requested_position_code' => 'jawatan dipohon',
'selected_ktm_assignment_id' => 'KTM',
'bank_name' => 'nama bank',
'bank_account_number' => 'no. akaun bank',
'ic_document' => 'dokumen kad pengenalan',
'bank_statement' => 'penyata bank',
];
}
private function validateDuplicateIc(Validator $validator, PusatMengundi $pusatMengundi): void
{
// SoftDeletes scope automatically excludes deleted_at IS NOT NULL records (e.g. soft-deleted
// KTM-created applicants). The whereNotIn further excludes 'cancelled' records (which are
// NOT soft-deleted) and 'deleted_by_ktm' records as an explicit safety layer.
$existing = Application::query()
->where('election_id', $pusatMengundi->election_id)
->where('ic_number', $this->input('ic_number'))
->whereNotIn('status', ['cancelled', 'deleted_by_ktm'])
->first();
if (! $existing instanceof Application) {
return;
}
if ($existing->source === 'created_by_ktm') {
$validator->errors()->add(
'ic_number',
'No. kad pengenalan ini telah didaftarkan oleh KTM. KTM perlu memadam rekod tersebut sebelum pemohon boleh mendaftar sendiri.',
);
return;
}
$validator->errors()->add(
'ic_number',
'No. kad pengenalan ini telah mempunyai permohonan untuk pilihanraya semasa.',
);
}
private function validateKtmVacancy(Validator $validator, PusatMengundi $pusatMengundi, string $roleCode): void
{
$assignmentId = (int) $this->input('selected_ktm_assignment_id');
if ($assignmentId <= 0) {
return;
}
if (! app(KtmVacancyService::class)->hasVacancyForAssignment($assignmentId, $pusatMengundi, $roleCode)) {
$validator->errors()->add(
'selected_ktm_assignment_id',
'KTM yang dipilih tidak sah atau kekosongan untuk jawatan ini telah penuh.',
);
}
}
}