$business->id, 'user_id' => $user?->id, 'type' => $type, 'title' => $title, 'message' => $message, 'data' => $data, 'channels' => ['in_app'], 'scheduled_at' => now(), 'sent_at' => now(), ]); } public function scanAndNotify(Business $business): array { $sent = []; if (Schema::hasTable('maintenance_preventive_schedules')) { $due = PreventiveSchedule::where('business_id', $business->id) ->where('is_active', true) ->where('next_due_at', '<=', now()->addDays(3)) ->count(); if ($due > 0) { $sent[] = $this->notify( $business, 'pm_due', 'PM سررسید', "{$due} برنامه PM در ۳ روز آینده سررسید دارد." ); } } if (Schema::hasTable('maintenance_spare_parts')) { $low = SparePart::where('business_id', $business->id) ->whereColumn('quantity', '<=', 'min_stock') ->count(); if ($low > 0) { $sent[] = $this->notify( $business, 'low_stock', 'موجودی کم', "{$low} قطعه یدکی زیر حداقل موجودی است." ); } } return array_filter($sent); } }