'decimal:2', 'expense_id' => 'integer', 'approved_by' => 'integer', 'added_by' => 'integer', 'batch_number' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; /* ============================================================ * Status (align these strings to your DB values) * ============================================================ */ public const STATUS_DRAFT = 'draft'; public const STATUS_PENDING = 'pending'; public const STATUS_APPROVED = 'approved'; public const STATUS_REIMBURSED = 'reimbursed'; public const STATUS_REJECTED = 'rejected'; public static function allowedStatuses(): array { return [ self::STATUS_DRAFT, self::STATUS_PENDING, self::STATUS_APPROVED, self::STATUS_REIMBURSED, self::STATUS_REJECTED, ]; } /* ============================================================ * Relationships (optional) * ============================================================ */ public function expense(): BelongsTo { return $this->belongsTo(Expense::class, 'expense_id'); } public function approver(): BelongsTo { // Change Admin::class to your actual admin/user model return $this->belongsTo(Admin::class, 'approved_by'); } public function addedBy(): BelongsTo { // Change Admin::class to your actual admin/user model return $this->belongsTo(Admin::class, 'added_by'); } /* ============================================================ * Scopes * ============================================================ */ public function scopeForSchoolYear(Builder $q, string $schoolYear): Builder { return $q->where('school_year', $schoolYear); } public function scopeForSemester(Builder $q, string $semester): Builder { return $q->where('semester', $semester); } public function scopeStatus(Builder $q, string $status): Builder { return $q->where('status', $status); } public function scopeInBatch(Builder $q, int $batchNumber): Builder { return $q->where('batch_number', $batchNumber); } /* ============================================================ * Helpers * ============================================================ */ public function markApproved(int $adminId): self { $this->status = self::STATUS_APPROVED; $this->approved_by = $adminId; $this->save(); return $this; } public function markReimbursed(?string $method = null, ?string $checkNumber = null): self { $this->status = self::STATUS_REIMBURSED; if ($method !== null) { $this->reimbursement_method = $method; } if ($checkNumber !== null) { $this->check_number = $checkNumber; } $this->save(); return $this; } /* ============================================================ * Optional validation helper (FormRequest/controller) * ============================================================ */ public static function rules(bool $updating = false): array { return [ 'amount' => [$updating ? 'sometimes' : 'required', 'numeric', 'min:0'], 'reimbursed_to' => ['nullable', 'string', 'max:255'], 'expense_id' => ['nullable', 'integer', 'exists:expenses,id'], 'description' => ['nullable', 'string', 'max:5000'], 'status' => ['nullable', 'string', 'in:'.implode(',', self::allowedStatuses())], 'receipt_path' => ['nullable', 'string', 'max:255'], 'approved_by' => ['nullable', 'integer'], 'added_by' => ['nullable', 'integer'], 'school_year' => ['nullable', 'string', 'max:20'], 'semester' => ['nullable', 'string', 'max:20'], 'check_number' => ['nullable', 'string', 'max:80'], 'reimbursement_method' => ['nullable', 'string', 'max:50'], 'batch_number' => ['nullable', 'integer', 'min:1'], ]; } }