'datetime', 'follow_up_date' => 'date', 'duration' => 'integer', 'talktime' => 'integer', 'ringtime' => 'integer', 'user_id' => 'integer', 'lead_id' => 'integer', 'contact_id' => 'integer', 'custom_data' => 'array', 'survey' => 'array', ]; // ── Relationships ───────────────────────────────────────────────────────── public function user() { return $this->belongsTo(User::class); } public function lead() { return $this->belongsTo(Lead::class); } public function contact() { return $this->belongsTo(Contact::class); } // ── Scopes ──────────────────────────────────────────────────────────────── public function scopeForLinkedid($query, string $linkedid) { return $query->where('linkedid', $linkedid); } public function scopeWithFollowUp($query) { return $query->whereNotNull('follow_up_date'); } public function scopeDueFollowUps($query) { return $query->whereNotNull('follow_up_date') ->whereDate('follow_up_date', '<=', now()->toDateString()); } // ── Helpers ─────────────────────────────────────────────────────────────── /** Human-readable call duration (e.g. "03:12") */ public function formattedDuration(): string { $secs = $this->duration ?? 0; return sprintf('%02d:%02d', intdiv($secs, 60), $secs % 60); } /** Returns true when a follow-up is scheduled and not yet past due. */ public function hasPendingFollowUp(): bool { return $this->follow_up_date && $this->follow_up_date->isFuture(); } }