# Fee Selection System

This document explains how the fee selection system works in the school management system.

## Overview

The fee selection system allows students to:
1. View all their unpaid fees
2. Select specific fees they want to pay
3. Process payment for selected fees through UddoktaPay

This system is similar to the one found on https://rescrutiny.eduboardresults.gov.bd/

## Components

### 1. Fee Selection Page (`fees/select_fees.php`)

This page displays all unpaid fees for a student with checkboxes to select which fees to pay.

Features:
- Shows all unpaid fees with due dates
- Allows selection of individual fees
- Calculates total amount for selected fees
- Provides "Select All" functionality
- Redirects to payment page with selected fees

### 2. Student Payment Page (`fees/student_payment.php`)

This page handles the payment process and has been modified to:
- Accept selected fees from the fee selection page
- Calculate payment amount based on selected fees
- Pass selected fees information to UddoktaPay
- Include selected fees in payment metadata

### 3. Payment Success Page (`fees/uddoktapay_success.php`)

This page processes successful payments and has been enhanced to:
- Handle payments for selected fees
- Update individual fee records with paid amounts
- Create payment records for each fee
- Distribute payment amounts across selected fees

### 4. My Fees Page (`fees/my_fees.php`)

This page has been updated to:
- Show a "Select Fees" button for students to choose specific fees
- Maintain the existing "Pay All" button for paying all fees at once

## How It Works

1. **Student Views Fees**: Student logs in and goes to "My Fees" page
2. **Select Fees**: Student clicks "Select Fees" button to choose specific fees
3. **Fee Selection**: Student selects desired fees and clicks "Pay Online"
4. **Payment Processing**: System calculates total for selected fees and redirects to payment page
5. **Payment Gateway**: Student completes payment through UddoktaPay
6. **Payment Verification**: System verifies payment and updates fee records
7. **Fee Updates**: Each selected fee is updated with the paid amount

## Database Handling

The system properly handles:
- Individual fee updates based on payment amounts
- Payment distribution across multiple fees
- Status updates (paid/partial) for fees
- Payment records for audit trail

## Security Features

- Only logged-in students can access the fee selection page
- Fee selection is tied to the specific student
- Payment amounts are validated
- Database transactions ensure data consistency

## Error Handling

- Fallback to paying all fees if selection fails
- Proper error messages for payment failures
- Validation of selected fees before processing