<?php

include('nav-master.php');
include('response.php');








?>

<div style="margin-top: 15px; padding-left: 12px; "  class="hp-main-layout-content">
<div class="row mb-32 gy-32">
				<div class="col-12">
        <div class="page-header-modern">
            <h2 class="header-modern">Master</h2>

    <div class="user-dropdown dropdown">
        <button class="btn btn-user" type="button" data-toggle="dropdown">
            <i class=""></i>
            <span class="user-name capitalize"><?php echo $_SESSION['role']; ?></span>
            <span class="caret"></span>
        </button>

        <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
            <li>
                <a class="dropdown-item" href="">
                    <i class="fa fa-user me-2"></i>   <?php echo strtok($_SESSION['user_name'], ' ');?>
                </a>
            </li>

            <li>
                <a class="dropdown-item" href="Admin/payment-details.php">
                    <i class="fa fa-credit-card"></i> Billing history
                </a>
            </li>

            <li>
                <a class="dropdown-item" href="Admin/company-profile.php">
                    <i class="fa fa-cog me-2"></i> Settings
                </a>
            </li>

            <li><hr class="dropdown-divider"></li>

            <li>
                <a class="dropdown-item text-danger" href="logout.php">
                    <i class="fa fa-sign-out me-2"></i> Sign Out
                </a>
            </li>
        </ul>
        </div>
    </div>
</div>


				
            <div class="col-lg-12">
                <div class="card">
                    
                            
        <div class="card-body">
		<!-- <hr> -->

		<div id="response" class="alert alert-success" style="display:none;">
			<a href="#" class="close" data-dismiss="alert">&times;</a>
			<div class="message"></div>
		</div>

						
<?php


$company_id = (int) ($_GET['id'] ?? 0);
if ($company_id <= 0) die("Invalid company");

$stmt = $conn->prepare("
    SELECT 
        p.id,
        p.amount,
        p.currency,
        p.status,
        p.reference,
        p.paid_at,
        p.created_at,
        s.plan
    FROM payments p
    LEFT JOIN subscriptions s ON s.id = p.subscription_id
    WHERE p.company_id = ?
    ORDER BY p.created_at DESC
");
$stmt->bind_param("i", $company_id);
$stmt->execute();
$payments = $stmt->get_result();
?>



<h4>Subscription Receipts</h4>

<a href="master-sub.php" class="btn btn-secondary btn-sm mb-3">
    ← Back
</a>

<table style="margin-top:20px" class="table table-bordered table-sm">
<thead class="table-light">
<tr>
    <th>#</th>
    <th>Plan</th>
    <th>Amount</th>
    <th>Status</th>
    <th>Reference</th>
    <th>Paid At</th>
    <th>Receipt</th>
</tr>
</thead>
<tbody>

<?php $i=1; while ($row = $payments->fetch_assoc()): ?>
<tr>
    <td><?= $i++ ?></td>
    <td><?= ucfirst($row['plan'] ?? 'N/A') ?></td>
    <td><?= $row['currency'] ?> <?= number_format($row['amount'], 2) ?></td>
    <td>
        <span class="badge bg-<?= $row['status']=='success'?'success':'warning' ?>">
            <?= ucfirst($row['status']) ?>
        </span>
    </td>
    <td><?= htmlspecialchars($row['reference']) ?></td>
    <td><?= $row['paid_at'] ? date('d M Y', strtotime($row['paid_at'])) : '-' ?></td>
    <td>
        <?php if ($row['status'] === 'success'): ?>
            <a href="master-receipt.php?ref=<?= urlencode($row['reference']) ?>" 
               class="btn btn-sm btn-primary" target="_blank">
               View Receipt
            </a>
        <?php else: ?>
            —
        <?php endif; ?>
    </td>
</tr>
<?php endwhile; ?>

</tbody>
</table>


                                   

		


		
             
		
 <!-- Plugin -->
 	
 	
    <script src="app-assets/js/plugin/swiper-bundle.min.js"></script>
    <script src="app-assets/js/plugin/jquery.mask.min.js"></script>
    <script src="app-assets/js/plugin/autocomplete.min.js"></script>
    <script src="app-assets/js/plugin/moment.min.js"></script>

    <!-- Layouts -->
    <script src="app-assets/js/layouts/header-search.js"></script>
    <script src="app-assets/js/layouts/sider.js"></script>
    <script src="app-assets/js/components/input-number.js"></script>

    <!-- Base -->
    <script src="app-assets/js/base/index.js"></script>
    <!-- Customizer -->
    <script src="app-assets/js/customizer.js"></script>

    <!-- Charts -->
    <script src="app-assets/js/plugin/apexcharts.min.js"></script>
    <script src="app-assets/js/charts/apex-chart.js"></script>

    <!-- Cards -->
    <script src="app-assets/js/cards/card-advance.js"></script>
    <script src="app-assets/js/cards/card-analytic.js"></script>
    <script src="app-assets/js/cards/card-statistic.js"></script>

    <!-- Pages -->
    <script src="app-assets/js/pages/dashboard-ecommerce.js"></script>

    <!-- Custom -->
    <script src="assets/js/main.js"></script>  
	
	
	<script> 
	const textarea = document.getElementById('auto-resize-textarea');

textarea.addEventListener('input', () => {
  textarea.style.height = 'auto'; // Reset height to recalculate
  textarea.style.height = textarea.scrollHeight + 'px'; // Set height based on scrollHeight
});

// Optional: Initial resize if content is pre-filled
textarea.style.height = 'auto';
textarea.style.height = textarea.scrollHeight + 'px';
</script>
</body>


</html>