# معماری — تسک ۱۶: ماژول داشبورد دکتر ## ساختار فایل‌ها ``` src/Module/Representation/ ├── Controller/ │ └── RepresentationController.php ├── Service/ │ ├── DashboardService.php ← آمار کلی │ ├── IncomeService.php ← محاسبه درآمد │ └── AppointmentReportService.php ← گزارش نوبت‌ها ├── Repository/ │ └── RepresentationRepository.php ← کوئری‌های پیچیده آماری └── DTO/ └── Response/ ├── DashboardResponse.php ├── YearlyIncomeResponse.php └── AppointmentListResponse.php ``` ## نمودار جریان ``` GET /representation/{uuid} │ ▼ DashboardService ├─► شمارش appointments (ماه جاری، کل، pending) ├─► جمع payments (ماه جاری، کل) └─► average_rating از doctors.average_rating ``` ## کوئری درآمد سالانه (بر اساس ماه‌های شمسی) ```php // RepresentationRepository.php // توجه: محاسبه بر اساس ماه شمسی است، نه میلادی // JalaliDateService بازه timestamp هر ماه را می‌دهد public function getMonthIncome(int $representationId, int $startTs, int $endTs): float { return (float) $this->createQueryBuilder('p') ->select('SUM(p.amount)') ->where('p.representationId = :repr') ->andWhere('p.status = :status') ->andWhere('p.createdAt >= :start') ->andWhere('p.createdAt < :end') ->setParameters([ 'repr' => $representationId, 'status' => 'received', // نه 'paid'! 'start' => (new \DateTime())->setTimestamp($startTs), 'end' => (new \DateTime())->setTimestamp($endTs), ]) ->getQuery() ->getSingleScalarResult() ?? 0.0; } ```