?????????????? ?????????????? Debug Fee Report

Debug Fee Report System

1. Database Connection Test"; if ($conn) { echo "

✓ Database connection successful

"; } else { echo "

✗ Database connection failed

"; exit; } // 2. Check if tables exist echo "

2. Table Existence Check

"; $tables_check = "SHOW TABLES"; $tables_result = $conn->query($tables_check); $existing_tables = array(); if ($tables_result) { while ($table_row = $tables_result->fetch_array()) { $existing_tables[] = $table_row[0]; } if (in_array('fees', $existing_tables)) { echo "

✓ 'fees' table exists

"; } else { echo "

✗ 'fees' table does not exist

"; } if (in_array('accounts', $existing_tables)) { echo "

✓ 'accounts' table exists

"; } else { echo "

✗ 'accounts' table does not exist

"; } if (in_array('admission', $existing_tables)) { echo "

✓ 'admission' table exists

"; } else { echo "

! 'admission' table does not exist (this is okay)

"; } } // 3. Check table data counts echo "

3. Data Count Check

"; $fees_count_sql = "SELECT COUNT(*) as count FROM fees"; $fees_count_result = $conn->query($fees_count_sql); if ($fees_count_result) { $fees_count = $fees_count_result->fetch_assoc()['count']; if ($fees_count > 0) { echo "

✓ Fees table has $fees_count records

"; } else { echo "

✗ Fees table is empty (0 records)

"; } } $accounts_count_sql = "SELECT COUNT(*) as count FROM accounts"; $accounts_count_result = $conn->query($accounts_count_sql); if ($accounts_count_result) { $accounts_count = $accounts_count_result->fetch_assoc()['count']; if ($accounts_count > 0) { echo "

✓ Accounts table has $accounts_count records

"; } else { echo "

✗ Accounts table is empty (0 records)

"; } } // 4. Show sample data from fees table echo "

4. Sample Data from Fees Table

"; $sample_fees_sql = "SELECT * FROM fees ORDER BY id DESC LIMIT 3"; $sample_fees_result = $conn->query($sample_fees_sql); if ($sample_fees_result && $sample_fees_result->num_rows > 0) { echo ""; echo ""; while($row = $sample_fees_result->fetch_assoc()) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
IDAdmission NoStudent NameCourseTotal FeeDue AmountReceived AmountPayment Date
" . $row['id'] . "" . $row['admission_no'] . "" . $row['student_name'] . "" . $row['course_name'] . "₹" . number_format($row['total_fee'], 2) . "₹" . number_format($row['due_amount'], 2) . "₹" . number_format($row['received_amount'], 2) . "" . $row['payment_date'] . "
"; } else { echo "

No data found in fees table

"; } // 5. Show sample data from accounts table echo "

5. Sample Data from Accounts Table

"; $sample_accounts_sql = "SELECT * FROM accounts ORDER BY id DESC LIMIT 3"; $sample_accounts_result = $conn->query($sample_accounts_sql); if ($sample_accounts_result && $sample_accounts_result->num_rows > 0) { echo ""; echo ""; while($row = $sample_accounts_result->fetch_assoc()) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
IDAdmission NoTotal FeesDue AmountPaid AmountReceived Amount
" . $row['id'] . "" . $row['admission_no'] . "₹" . number_format($row['total_fees'], 2) . "₹" . number_format($row['due_amount'], 2) . "₹" . number_format($row['paid_amount'], 2) . "₹" . number_format($row['received_amount'], 2) . "
"; } else { echo "

No data found in accounts table

"; } // 6. Test the exact query used in fee-report.php echo "

6. Test Fee Report Query

"; $test_sql = "SELECT f.*, COALESCE(a.due_amount, f.total_fee) as account_due_amount, COALESCE(a.paid_amount, 0) as account_paid_amount, COALESCE(a.received_amount, 0) as account_received_amount FROM fees f LEFT JOIN accounts a ON f.admission_no = a.admission_no ORDER BY f.id DESC LIMIT 5"; echo "

Query:

"; echo "
" . $test_sql . "
"; $test_result = $conn->query($test_sql); if (!$test_result) { echo "

✗ Query failed: " . $conn->error . "

"; } else { $num_rows = $test_result->num_rows; echo "

✓ Query executed successfully. Rows returned: $num_rows

"; if ($num_rows > 0) { echo ""; echo ""; while($row = $test_result->fetch_assoc()) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
Admission NoStudent NameCourseTotal FeeAccount DueReceivedDate
" . $row['admission_no'] . "" . $row['student_name'] . "" . $row['course_name'] . "₹" . number_format($row['total_fee'], 2) . "₹" . number_format($row['account_due_amount'], 2) . "₹" . number_format($row['received_amount'], 2) . "" . $row['payment_date'] . "
"; } } // 7. Test student details API if (isset($sample_fees_result) && $sample_fees_result->num_rows > 0) { $sample_fees_result = $conn->query($sample_fees_sql); // Re-run query $test_row = $sample_fees_result->fetch_assoc(); $test_admission = $test_row['admission_no']; echo "

7. Test Student Details API

"; echo "

Testing with admission number: $test_admission

"; echo ""; echo "
"; } $conn->close(); ?>

Next Steps: