<?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>
             <img src="images/icon/invoice360-user.png" height=30px; width=30px;>
            <span class="caret"></span>
        </button>

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


$query = "
    SELECT 
        c.id AS company_id,
        c.company_name,
        c.company_email,
        s.plan,
        s.status,
        s.started_at,
        s.created_at,
        s.ends_at
    FROM company c
    LEFT JOIN subscriptions s ON s.company_id = c.id
    ORDER BY c.created_at DESC
";

$result = $conn->query($query);
?>




<h3>Company Subscriptions</h3>

<table class="table table-bordered table-sm">
<thead class="table-light">
<tr>
    <th>#</th>
    <th>Company</th>
    <th>Admin Email</th>
    <th>Plan</th>
    <th>Status</th>
    <th>Reg.Date</th>
    <th>Expiry</th>
    <th>Actions</th>
</tr>
</thead>
<tbody>

<?php $i = 1; while ($row = $result->fetch_assoc()): ?>
<tr>
    <td><?= $i++ ?></td>
    <td><?= htmlspecialchars($row['company_name']) ?></td>
    <td><?= htmlspecialchars($row['company_email']) ?></td>
    <td><?= ucfirst($row['plan'] ?? 'none') ?></td>
    <td><?= ucfirst($row['status'] ?? 'inactive') ?></td>
    <td><?= $row['created_at'] ? date('d M Y', strtotime($row['created_at'])) : '-' ?></td>
    <td><?= $row['ends_at'] ? date('d M Y', strtotime($row['ends_at'])) : '-' ?></td>
    <td>
        <a href="master-admin-override.php?id=<?= $row['company_id'] ?>" class="btn btn-sm btn-warning">
            Override
        </a>

         <a href="master-receipt-list.php?id=<?= $row['company_id'] ?>" 
       class="btn btn-sm btn-info">View Receipts</a>

        <a href="master-delete-company.php?id=<?= $row['company_id'] ?>"
           class="btn btn-sm btn-danger"
           onclick="return confirm('This will permanently delete this company. Continue?')">
            Delete
        </a>
    </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>