                    <!-- قسم الدفعات الشهرية -->
                    <div class="mb-5">
                        <h4 class="border-bottom pb-2 mb-4">
                            <i class="fas fa-calendar-alt me-2"></i> الدفعات الشهرية خلال الفترة
                        </h4>
                        
                        <?php
                        // استعلام الدفعات الشهرية
                        $query = "SELECT mp.*, m.first_name, m.last_name, c.name as category_name, u.full_name as created_by_name
                                FROM monthly_payments mp
                                JOIN members m ON mp.member_id = m.id
                                JOIN categories c ON m.category_id = c.id
                                LEFT JOIN users u ON mp.created_by = u.id
                                WHERE (mp.payment_month BETWEEN :start_date AND :end_date OR mp.payment_date BETWEEN :start_date AND :end_date)
                                AND mp.payment_status = 'paid'
                                ORDER BY mp.payment_month DESC, m.first_name ASC";
                        $monthlyPayments = fetchAll($query, [':start_date' => $startDate, ':end_date' => $endDate]);
                        
                        // إحصائيات الدفعات الشهرية
                        $totalMonthlyPayments = 0;
                        $monthlyStats = [];
                        
                        foreach ($monthlyPayments as $payment) {
                            $totalMonthlyPayments += (float)$payment['amount_paid'];
                            
                            // تجميع الإحصائيات حسب الشهر
                            $month = date('m/Y', strtotime($payment['payment_month']));
                            if (!isset($monthlyStats[$month])) {
                                $monthlyStats[$month] = [
                                    'count' => 0,
                                    'total' => 0
                                ];
                            }
                            $monthlyStats[$month]['count']++;
                            $monthlyStats[$month]['total'] += (float)$payment['amount_paid'];
                        }
                        
                        // ترتيب الإحصائيات حسب الشهر (تنازلياً)
                        krsort($monthlyStats);
                        
                        if (count($monthlyPayments) > 0):
                        ?>
                        
                        <!-- ملخص الدفعات الشهرية -->
                        <div class="row mb-4">
                            <div class="col-md-4">
                                <div class="card bg-light h-100">
                                    <div class="card-body text-center">
                                        <h6 class="card-title">إجمالي الدفعات</h6>
                                        <h4 class="text-primary"><?php echo count($monthlyPayments); ?></h4>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="card bg-light h-100">
                                    <div class="card-body text-center">
                                        <h6 class="card-title">إجمالي المبالغ</h6>
                                        <h4 class="text-success">
                                            <?php echo number_format($totalMonthlyPayments, 2); ?> <?php echo CURRENCY; ?>
                                        </h4>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="card bg-light h-100">
                                    <div class="card-body text-center">
                                        <h6 class="card-title">متوسط الدفعة</h6>
                                        <h4 class="text-info">
                                            <?php 
                                            $average = count($monthlyPayments) > 0 ? $totalMonthlyPayments / count($monthlyPayments) : 0;
                                            echo number_format($average, 2); 
                                            ?> <?php echo CURRENCY; ?>
                                        </h4>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!-- إحصائيات حسب الشهر -->
                        <h5 class="text-primary mb-3">
                            <i class="fas fa-chart-bar me-2"></i> إحصائيات حسب الشهر
                        </h5>
                        <div class="table-responsive mb-4">
                            <table class="table table-bordered">
                                <thead class="table-light">
                                    <tr>
                                        <th>الشهر</th>
                                        <th>عدد الدفعات</th>
                                        <th>إجمالي المبالغ</th>
                                        <th>متوسط الدفعة</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($monthlyStats as $month => $stats): ?>
                                    <tr>
                                        <td><?php echo $month; ?></td>
                                        <td><?php echo $stats['count']; ?></td>
                                        <td class="text-success"><?php echo number_format($stats['total'], 2); ?> <?php echo CURRENCY; ?></td>
                                        <td><?php echo number_format($stats['total'] / $stats['count'], 2); ?> <?php echo CURRENCY; ?></td>
                                    </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                        
                        <!-- تفاصيل الدفعات الشهرية -->
                        <h5 class="text-primary mb-3">
                            <i class="fas fa-list me-2"></i> تفاصيل الدفعات الشهرية
                        </h5>
                        <div class="table-responsive">
                            <table class="table table-striped table-hover">
                                <thead class="table-light">
                                    <tr>
                                        <th>#</th>
                                        <th>المنخرط</th>
                                        <th>الفئة</th>
                                        <th>شهر الدفع</th>
                                        <th>تاريخ الدفع</th>
                                        <th>المبلغ</th>
                                        <th>طريقة الدفع</th>
                                        <th>ملاحظات</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php 
                                    $counter = 1;
                                    foreach ($monthlyPayments as $payment): 
                                    ?>
                                    <tr>
                                        <td><?php echo $counter++; ?></td>
                                        <td><?php echo $payment['first_name'] . ' ' . $payment['last_name']; ?></td>
                                        <td><?php echo $payment['category_name']; ?></td>
                                        <td><?php echo date('m/Y', strtotime($payment['payment_month'])); ?></td>
                                        <td><?php echo formatDate($payment['payment_date']); ?></td>
                                        <td class="text-success"><?php echo number_format((float)$payment['amount_paid'], 2); ?> <?php echo CURRENCY; ?></td>
                                        <td><?php echo $payment['payment_method']; ?></td>
                                        <td><?php echo $payment['notes']; ?></td>
                                    </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                        <?php else: ?>
                        <div class="alert alert-info">
                            <i class="fas fa-info-circle me-2"></i> لا توجد دفعات شهرية مسجلة خلال هذه الفترة.
                        </div>
                        <?php endif; ?>
                    </div>
