<?php $this->load->view("common/header"); ?>
<body>
  <div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
      <div class="navbar-header">
        <button data-target=".navbar-collapse" data-toggle="collapse" class="navbar-toggle" type="button"> <span class="clip-list-2"></span> </button>
        <?php $this->load->view("common/logo"); ?>
      </div>
      <div class="navbar-tools">
        <?php $this->load->view("common/notifications.php"); ?>
      </div>
    </div>
  </div>
  <div class="main-container">
    <div class="navbar-content">
      <?php $this->load->view("common/navigation"); ?>
    </div>
    <div class="main-content">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <ol class="breadcrumb">
                    <li><a href="<?php echo base_url('dashboard'); ?>">Dashboard</a></li>
                    <li><a href="#">Reports</a></li>
                    <li class="active">Customer Compliments – Birthday</li>
                </ol>
                <div class="page-header"><h1>Birthday Wishes</h1></div>
            </div>
        </div>

        <!-- Month Filter -->
        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <form method="post" action="<?php echo base_url('reports_loan/customer_compliments'); ?>">
                            <div class="col-sm-3">
                                <div class="form-group">
                                    <label>Select Month</label>
                                    <input type="text" name="birthday_month" class="form-control month-picker" 
                                           value="<?php echo $selected_month; ?>" placeholder="YYYY-MM">
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <div class="form-group"><br>
                                    <button type="submit" class="btn btn-primary">Show Birthdays</button>
                                    <button type="button" class="btn btn-default" 
                                            onclick="window.location='<?php echo base_url('reports_loan/customer_compliments'); ?>'">
                                        Current Month
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <!-- Printable Header -->
        <div id="printableArea" style="display:none;">
            <h4>Birthday Compliments – <?php echo date('F Y', strtotime($selected_month . '-01')); ?></h4>
            <p><strong>Total Customers:</strong> <?php echo count($customers); ?></p>
        </div>

        <!-- Table -->
        <table class="table table-bordered table-hover dataTable" id="birthday_table">
            <thead>
                <tr>
                    <th width="8%">#</th>
                    <th>Customer Name</th>
                    <th>Mobile</th>
                    <th>Date of Birth</th>
                    <th>Compliment</th>
                </tr>
            </thead>
            <tbody>
                <?php if ($customers): ?>
                    <?php $i = 1; foreach ($customers as $c): ?>
                        <tr>
                            <td><?php echo $i++; ?></td>
                            <td><?php echo htmlspecialchars($c['customer_name']); ?></td>
                            <td><?php echo htmlspecialchars($c['cus_mobile']); ?></td>
                            <td><?php echo date('d M Y', strtotime($c['date_of_birth'])); ?></td>
                            <td class="text-center">Yes</td>
                        </tr>
                    <?php endforeach; ?>
                <?php else: ?>
                    <tr><td colspan="6" class="text-center text-muted">No birthdays in this month.</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
    <div class="footer clearfix">
      <div class="footer-inner"> <?php echo date("Y"); ?> &copy; A.S.S.K Loan Management System </div>
      <div class="footer-items"> <span class="go-top"><i class="clip-chevron-up"></i></span> </div>
    </div>
    <?php $this->load->view("common/footer"); ?>
    <!-- Scripts -->
    <script src="<?php echo asset_url(); ?>js/jquery.dataTables.min.js"></script>
    <script src="<?php echo asset_url(); ?>js/dataTables.bootstrap.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.6/js/dataTables.buttons.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.print.min.js"></script>
    <script src="<?php echo asset_url(); ?>js/bootstrap-datetimepicker.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>

    <script>
    $(document).ready(function() {
        // Month Picker
        $('.month-picker').datetimepicker({
            format: 'YYYY-MM',
            viewMode: 'months',
            defaultDate: moment('<?php echo $selected_month; ?>', 'YYYY-MM')
        });
    
        // DataTable
        $('#birthday_table').DataTable({
            dom: 'Bfrtip',
            buttons: [{
                extend: 'print',
                text: 'Print',
                title: '',
                messageTop: function() { return $('#printableArea').html(); },
                exportOptions: { columns: [0,1,2,3,4,5] }
            }],
            pageLength: 25,
            order: [[5, 'asc'], [1, 'asc']], // Sort by Day, then Name
            language: { emptyTable: "No birthdays in selected month." }
        });
    });
    </script>
    
    <style>
    @media print { #printableArea { display: block !important; } }
    </style>
</body>
</html>