Path : /home/vishqocm/pcib.in/student/
File Upload :
Current File : /home/vishqocm/pcib.in/student/payment_receipt.php

<?php
// Start session
session_start();

// Check if user is logged in
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'student') {
    header('Location: ../login.php');
    exit();
}

// Check if receipt data exists in session
if (!isset($_SESSION['payment_receipt'])) {
    header('Location: payments.php');
    exit();
}

// Get receipt data from session
$receipt = $_SESSION['payment_receipt'];

// Include header
include_once 'includes/header.php';

// Format payment date
$payment_date = new DateTime($receipt['payment_date']);
$formatted_date = $payment_date->format('d M Y, h:i A');

// Generate receipt number (based on provided payment ID or receipt ID)
$receipt_number = !empty($receipt['receipt_id']) ? $receipt['receipt_id'] : 'RCP-' . date('Ymd') . '-' . $receipt['payment_id'];

// Get payment plan display and installments
$payment_plan_display = 'Full Payment';
$total_installments = 1;
if ($receipt['payment_plan'] === 'monthly') {
    $payment_plan_display = 'Monthly Plan';
    $total_installments = 3; // Default to 3 for display
} else if ($receipt['payment_plan'] === 'half_duration' || $receipt['payment_plan'] === 'six_month') {
    $payment_plan_display = 'Installment Plan';
    $total_installments = 2; // Default to 2 for display
} else if ($receipt['payment_plan'] === 'quarterly') {
    $payment_plan_display = 'Quarterly Plan';
    $total_installments = 4; // Default to 4 for display
}

// For next payment date (if installment plan)
$next_payment_date = date('d M Y', strtotime('+1 month'));
?>

<div class="container py-4">
    <div class="text-center mb-4">
        <h4 class="mb-3">Payment Receipt</h4>
        <p class="text-muted">Your payment has been completed successfully.</p>
        <div class="mb-3">
            <button class="btn btn-primary me-2" onclick="showReceipt()">
                <i class="fas fa-file-invoice me-2"></i> View Receipt
            </button>
            <a href="payments.php" class="btn btn-secondary">
                <i class="fas fa-arrow-left me-2"></i> Back to Payments
            </a>
        </div>
    </div>
</div>

<!-- Payment Receipt Modal -->
<div class="modal fade" id="receiptModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header bg-primary text-white">
                <h5 class="modal-title">
                    <i class="fas fa-file-invoice me-2"></i> Payment Receipt
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body p-4" id="receiptContent">
                <div class="receipt-container" id="receiptToPrint">
                    <div class="receipt-header">
                        <div class="row align-items-center">
                            <div class="col-md-3 text-center">
                                <?php if (!empty($receipt['institute_logo'])): ?>
                                <img src="../<?php echo $receipt['institute_logo']; ?>" class="receipt-logo" alt="Institute Logo" style="max-width: 100px; max-height: 80px;" onerror="this.src='../assets/img/logo.png'; this.onerror='';">
                                <?php else: ?>
                                <img src="../assets/img/logo.png" class="receipt-logo" alt="Institute Logo" style="max-width: 100px; max-height: 80px;">
                                <?php endif; ?>
                            </div>
                            <div class="col-md-9 text-center text-md-start">
                                <h3 class="receipt-title mb-0"><?php echo htmlspecialchars($receipt['institute_name']); ?></h3>
                                <p class="receipt-subtitle mb-0 small"><?php echo nl2br(htmlspecialchars($receipt['institute_address'])); ?></p>
                                <p class="receipt-subtitle small mb-0">
                                    <?php if (!empty($receipt['institute_phone'])): ?>Phone: <?php echo htmlspecialchars($receipt['institute_phone']); ?> | <?php endif; ?>
                                    <?php if (!empty($receipt['institute_email'])): ?>Email: <?php echo htmlspecialchars($receipt['institute_email']); ?><?php endif; ?>
                                </p>
                            </div>
                        </div>
                        <div class="text-center mt-3 mb-2">
                            <h4 class="border-bottom border-top py-2">PAYMENT RECEIPT</h4>
                        </div>
                    </div>
                    
                    <div class="receipt-body">
                        <div class="row g-3 mb-2">
                            <div class="col-md-6">
                                <div class="card h-100">
                                    <div class="card-header bg-light py-1">
                                        <h6 class="mb-0">Student Information</h6>
                                    </div>
                                    <div class="card-body py-2">
                                        <p class="mb-1 small"><strong>Name:</strong> <?php echo htmlspecialchars($receipt['student_name']); ?></p>
                                        <p class="mb-1 small"><strong>Email:</strong> <?php echo htmlspecialchars($receipt['email']); ?></p>
                                        <p class="mb-0 small"><strong>Phone:</strong> <?php echo !empty($receipt['phone']) ? htmlspecialchars($receipt['phone']) : 'N/A'; ?></p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="card h-100">
                                    <div class="card-header bg-light py-1">
                                        <h6 class="mb-0">Payment Information</h6>
                                    </div>
                                    <div class="card-body py-2">
                                        <p class="mb-1 small"><strong>Receipt No:</strong> <?php echo htmlspecialchars($receipt_number); ?></p>
                                        <p class="mb-1 small"><strong>Date:</strong> <?php echo $formatted_date; ?></p>
                                        <p class="mb-0 small"><strong>Method:</strong> <?php echo htmlspecialchars($receipt['payment_method']); ?></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="card mb-3">
                            <div class="card-header bg-light py-1">
                                <h6 class="mb-0">Course Details & Payment Summary</h6>
                            </div>
                            <div class="card-body p-0">
                                <div class="table-responsive">
                                    <table class="table table-bordered table-sm mb-0">
                                        <thead class="table-light">
                                            <tr>
                                                <th width="40%">Course Description</th>
                                                <th width="15%">Fee Type</th>
                                                <th width="25%">Payment Plan</th>
                                                <th width="20%" class="text-end">Amount</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td>
                                                    <strong><?php echo htmlspecialchars($receipt['course_title']); ?></strong><br>
                                                    <small class="text-muted"><?php echo htmlspecialchars($receipt['payment_for']); ?></small>
                                                </td>
                                                <td><?php echo htmlspecialchars($receipt['payment_for']); ?></td>
                                                <td>
                                                <?php 
                                                $payment_plan = $receipt['payment_plan'];
                                                if ($payment_plan === 'monthly') {
                                                    echo "Monthly Plan<br><small class=\"text-muted\">({$total_installments} monthly payments)</small>";
                                                } else if ($payment_plan === 'half_duration' || $payment_plan === 'six_month') {
                                                    echo "Installment Plan<br><small class=\"text-muted\">({$total_installments} installments)</small>";
                                                } else {
                                                    echo "Full Payment<br><small class=\"text-muted\">(One-time payment)</small>";
                                                }
                                                ?>
                                                </td>
                                                <td class="text-end">₹<?php echo number_format($receipt['amount'], 2); ?></td>
                                            </tr>
                                            <tr>
                                                <td colspan="3" class="text-end"><strong>Total Paid:</strong></td>
                                                <td class="text-end"><strong>₹<?php echo number_format($receipt['amount'], 2); ?></strong></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        
                        <?php if (($payment_plan === 'monthly' || $payment_plan === 'half_duration' || $payment_plan === 'six_month') && $total_installments > 1): ?>
                        <div class="alert alert-info py-2 small mb-3">
                            <strong>Note:</strong> This is an installment payment. 
                            Next payment will be due on <?php echo $next_payment_date; ?>.
                        </div>
                        <?php endif; ?>
                        
                        <div class="row">
                            <div class="col-md-12 d-flex flex-column justify-content-end">
                                <div class="text-end mt-3">
                                    <p class="mb-5 pt-5 small">Authorized Signature</p>
                                    <hr style="width: 150px; border-top: 1px solid #333; float: right;">
                                    <p class="small mb-0">For <?php echo htmlspecialchars($receipt['institute_name']); ?></p>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="receipt-footer mt-3 pt-2 border-top small text-center">
                        <p class="mb-0">This is a computer generated receipt and does not require a physical signature.</p>
                        <p class="mb-0">For any queries, please contact: <?php echo !empty($receipt['institute_phone']) ? htmlspecialchars($receipt['institute_phone']) : 'Your Contact Phone'; ?> | 
                           <?php echo !empty($receipt['institute_email']) ? htmlspecialchars($receipt['institute_email']) : '[email protected]'; ?></p>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="printReceipt()">
                    <i class="fas fa-print me-2"></i> Print Receipt
                </button>
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<style>
.receipt-container {
    background-color: white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
}

.receipt-logo {
    max-height: 80px;
    max-width: 100%;
}

.receipt-title {
    color: #333;
    font-weight: 600;
}

.receipt-subtitle {
    color: #666;
}

.receipt-footer {
    color: #666;
    font-size: 12px;
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

@media print {
    body * {
        visibility: hidden;
    }
    
    #receiptToPrint, #receiptToPrint * {
        visibility: visible;
    }
    
    #receiptToPrint {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }
    
    .modal {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        background: white !important;
    }
    
    .modal-dialog {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
        transform: none !important;
    }
    
    .modal-content {
        border: none !important;
        box-shadow: none !important;
        background: white !important;
    }
    
    .modal-header, .modal-footer, .btn-close {
        display: none !important;
    }
    
    .card {
        border: 1px solid #ddd !important;
        margin-bottom: 15px !important;
    }
    
    .card-header {
        background-color: #f5f5f5 !important;
        padding: 8px 10px !important;
    }
    
    .card-body {
        padding: 10px !important;
    }
    
    h3 { font-size: 18px !important; }
    h4 { font-size: 16px !important; }
    h5, h6 { font-size: 14px !important; }
    p, .card-body p { font-size: 12px !important; margin-bottom: 6px !important; }
    
    .table th, .table td {
        padding: 6px !important;
        font-size: 12px !important;
    }
}
</style>

<script>
// Show receipt modal automatically when page loads
document.addEventListener('DOMContentLoaded', function() {
    showReceipt();
});

function showReceipt() {
    var receiptModal = new bootstrap.Modal(document.getElementById('receiptModal'));
    receiptModal.show();
}

function printReceipt() {
    const printContent = document.getElementById('receiptToPrint').innerHTML;
    const originalContent = document.body.innerHTML;
    
    document.body.innerHTML = printContent;
    window.print();
    document.body.innerHTML = originalContent;
    
    // Re-initialize receipt modal
    setTimeout(function() {
        showReceipt();
    }, 500);
}
</script>

<?php
// Clear receipt data from session after displaying
unset($_SESSION['payment_receipt']);

include_once 'includes/footer.php';
?>