Path : /home/vishqocm/pcib.in/admin/ajax/
File Upload :
Current File : /home/vishqocm/pcib.in/admin/ajax/get_payment_details.php

<?php
// Include database configuration
require_once '../database/db_config.php';

// Check if admin is logged in
session_start();
if (!isset($_SESSION['user_id']) || ($_SESSION['role'] !== 'admin' && $_SESSION['role'] !== 'director')) {
    echo '<div class="alert alert-danger">Access denied. Please log in as an administrator.</div>';
    exit;
}

// Check if payment ID is provided
if (!isset($_GET['payment_id']) || !is_numeric($_GET['payment_id'])) {
    echo '<div class="alert alert-danger">Invalid payment ID.</div>';
    exit;
}

$payment_id = intval($_GET['payment_id']);

// Get payment details
$query = "SELECT p.*, 
          u.first_name, u.last_name, u.email, 
          c.title as course_title,
          a.first_name as admin_first_name, a.last_name as admin_last_name
          FROM payments p
          JOIN users u ON p.user_id = u.id
          JOIN courses c ON p.course_id = c.id
          LEFT JOIN users a ON p.marked_by = a.id
          WHERE p.id = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("i", $payment_id);
$stmt->execute();
$payment = $stmt->get_result()->fetch_assoc();

if (!$payment) {
    echo '<div class="alert alert-danger">Payment not found.</div>';
    exit;
}

// Format payment details
$status_badge_class = ($payment['status'] === 'completed') ? 'success' : 
                      (($payment['status'] === 'refunded') ? 'warning' : 'secondary');
?>

<div class="payment-details">
    <div class="row mb-4">
        <div class="col-md-6">
            <h6 class="fw-bold">Payment Information</h6>
            <p><strong>Amount:</strong> ₹<?php echo number_format($payment['amount'], 2); ?></p>
            <p><strong>Method:</strong> <?php echo ucfirst($payment['payment_method']); ?></p>
            <p><strong>Transaction ID:</strong> <?php echo htmlspecialchars($payment['transaction_id']); ?></p>
            <p><strong>Date:</strong> <?php echo date('M d, Y H:i:s', strtotime($payment['payment_date'])); ?></p>
            <p><strong>Status:</strong> 
                <span class="badge bg-<?php echo $status_badge_class; ?>">
                    <?php echo ucfirst($payment['status']); ?>
                </span>
            </p>
        </div>
        <div class="col-md-6">
            <h6 class="fw-bold">Student & Course</h6>
            <p><strong>Student:</strong> <?php echo htmlspecialchars($payment['first_name'] . ' ' . $payment['last_name']); ?></p>
            <p><strong>Email:</strong> <?php echo htmlspecialchars($payment['email']); ?></p>
            <p><strong>Course:</strong> <?php echo htmlspecialchars($payment['course_title']); ?></p>
            <p><strong>Marked By:</strong> 
                <?php 
                if (!empty($payment['admin_first_name'])) {
                    echo htmlspecialchars($payment['admin_first_name'] . ' ' . $payment['admin_last_name']);
                } else {
                    echo '<span class="text-muted">Not available</span>';
                }
                ?>
            </p>
        </div>
    </div>
    
    <?php if (!empty($payment['payment_details'])): ?>
    <div class="mb-3">
        <h6 class="fw-bold">Additional Details</h6>
        <div class="card">
            <div class="card-body bg-light">
                <?php echo nl2br(htmlspecialchars($payment['payment_details'])); ?>
            </div>
        </div>
    </div>
    <?php endif; ?>
    
    <div class="text-center mt-3">
        <a href="enrollment_payment.php?id=<?php echo $payment['course_id']; ?>" class="btn btn-sm btn-primary">
            <i class="fas fa-list"></i> View All Payments
        </a>
        <?php if ($payment['status'] === 'completed'): ?>
        <button class="btn btn-sm btn-warning refund-btn" 
                data-payment-id="<?php echo $payment['id']; ?>"
                data-amount="<?php echo $payment['amount']; ?>"
                data-bs-toggle="modal" 
                data-bs-target="#refundModal">
            <i class="fas fa-undo"></i> Refund
        </button>
        <?php endif; ?>
    </div>
</div>

<script>
// Initialize the refund button in the modal
$(document).ready(function() {
    $('.refund-btn').on('click', function() {
        var paymentId = $(this).data('payment-id');
        var amount = $(this).data('amount');
        
        $('#refundPaymentId').val(paymentId);
        $('#refundAmount').val(amount);
        
        // Hide current modal and show refund modal
        $('#paymentDetailsModal').modal('hide');
        setTimeout(function() {
            $('#refundModal').modal('show');
        }, 500);
    });
});
</script>