<style type="text/css">
    .nav-tabs-custom>.nav-tabs>li.active {
        border-top-color: #faa21c;
    }
</style>
<?php
$currency_symbol = $this->customlib->getSchoolCurrencyFormat();
?>
<div class="content-wrapper" style="min-height: 946px;">
    <section class="content-header">
        <h1>
            <i class="fa fa-line-chart"></i> <?php echo $this->lang->line('financial_reports'); ?> <small> </small>   </h1>
											<a href="<?php  echo base_url(); ?>uniformreport" class="col-md pull-right">Uniform Report</a>
                                            <b style="padding-left:5px;padding-right:5px;"class="pull-right"> | </b>												 
                                            <a href="<?php  echo base_url(); ?>admin/payroll/payrollreport" class="col-md pull-right">Payroll Report</a> 
                                            <b style="padding-left:5px;padding-right:5px;"class="pull-right"> | </b>
                                            <a href="<?php  echo base_url(); ?>admin/transaction/searchtransaction" class="col-md pull-right">Transaction Report</a>	
                                            <b style="padding-left:5px;padding-right:5px;"class="pull-right"> | </b>
                                            <a href="<?php  echo base_url(); ?>admin/transaction/studentacademicreport" class="col-md pull-right">Balance Fees Report</a>	
                                            <b style="padding-left:5px;padding-right:5px;"class="pull-right"> | </b>
    </section>
<!-- Main content --> 
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title"><i class="fa fa-balance-scale"></i> 
                        <?php echo $this->lang->line('outstandinguniforms'); ?>
                    </h3>
                </div>
                <div class="box-body">

                    <div class="row"> 
                        <div class="col-md-12">
                            <form id="reportForm" role="form" 
                                  action="<?php echo site_url('admin/BIreports/outstanding_uniforms'); ?>" 
                                  method="post" class="form-horizontal">
                                <?php echo $this->customlib->getCSRF(); ?> 

                                <!-- Filters -->
                                <div class="form-group">
                                    <div class="col-sm-4">
                                        <label>Report Type</label>
                                        <select id="report_type" name="report_type" class="form-control">
                                            <option value="summary" <?= ($report_type == 'summary') ? 'selected' : '' ?>>Summary</option>
                                            <option value="detailed" <?= ($report_type == 'detailed') ? 'selected' : '' ?>>Detailed</option>
                                        </select>
                                    </div>

                                    <div class="col-sm-4">
                                        <label><?php echo $this->lang->line('date_from'); ?></label>
                                        <input id="datefrom" name="date_from" type="text" class="form-control date"
                                            value="<?php echo set_value('date_from', date($this->customlib->getSchoolDateFormat())); ?>" readonly/>
                                    </div>

                                    <div class="col-sm-4">
                                        <label><?php echo $this->lang->line('date_to'); ?></label>
                                        <input id="dateto" name="date_to" type="text" class="form-control date"
                                            value="<?php echo set_value('date_to', date($this->customlib->getSchoolDateFormat())); ?>" readonly/>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="col-sm-4">
                                        <label>View Mode</label>
                                        <select id="view_mode" name="view_mode" class="form-control" onchange="toggleBreakdown()">
                                            <option value="overall" <?= ($view_mode == 'overall') ? 'selected' : '' ?>>Overall</option>
                                            <option value="broken" <?= ($view_mode == 'broken') ? 'selected' : '' ?>>Broken Down</option>
                                        </select>
                                    </div>

                                    <!-- Class and Level filters -->
                                    <div class="col-sm-4" id="class_filter" style="display:none;">
                                        <label>Level From</label>
                                        <select id="level_from" name="level_from" class="form-control">
                                            <option value="">-- Select Level --</option>
                                            <?php foreach ($levellist as $level): ?>
                                                <option value="<?php echo $level['id']; ?>">
                                                    <?php echo $level['class']; ?>
                                                </option>
                                            <?php endforeach; ?>
                                        </select>
                                    </div>

                                    <div class="col-sm-4" id="level_filter" style="display:none;">
                                        <label>Level To</label>
                                        <select id="level_to" name="level_to" class="form-control">
                                            <option value="">-- Select Level --</option>
                                            <?php foreach ($levellist as $level): ?>
                                                <option value="<?php echo $level['id']; ?>">
                                                    <?php echo $level['class']; ?>
                                                </option>
                                            <?php endforeach; ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="col-sm-12">
                                        <button type="submit" name="search" value="search_filter" class="btn btn-primary btn-sm pull-right">
                                            <i class="fa fa-search"></i> <?php echo $this->lang->line('search'); ?>
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-12">
                            <div class="box box-success">
                                <div class="box-header with-border">
                                    <h3 class="box-title">Outstanding Uniforms Report</h3>
                                </div>
                                <div class="box-body">
                                    <div class="table-responsive">
                                        <table class="table table-bordered table-striped">
                                            <thead>
                                                <tr>
                                                    <th>Date</th>
                                                    <th>Student Name</th>
                                                    <th>Student ID</th>
                                                    <th>Uniform Name</th>
                                                    <th>Invoice Number</th>
                                                    <th>Owing Balance</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php 
                                                $grand_total = 0; 
                                                if (!empty($outstanding_uniforms)) {
                                                    foreach ($outstanding_uniforms as $row) {
                                                        $grand_total += $row['amount'];
                                                ?>
                                                    <tr>
                                                        <td><?php echo htmlspecialchars($row['created_date']); ?></td>
                                                        <td><?php echo htmlspecialchars($row['name']); ?></td>
                                                        <td><?php echo htmlspecialchars($row['student_id']); ?></td>
                                                        <td><?php echo htmlspecialchars($row['description']); ?></td>
                                                        <td><?php echo htmlspecialchars($row['batch_num']); ?></td>
                                                        <td style="text-align:right;"><?php echo number_format($row['amount'], 2); ?></td>
                                                    </tr>
                                                <?php 
                                                    }
                                                } else { 
                                                ?>
                                                    <tr>
                                                        <td colspan="5" class="text-center">No records found</td>
                                                    </tr>
                                                <?php } ?>
                                            </tbody>
                                            <tfoot>
                                                <tr>
                                                    <th colspan="4" style="text-align:right;">Grand Total</th>
                                                    <th><?php echo number_format($grand_total, 2); ?></th>
                                                </tr>
                                            </tfoot>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </div> <!-- /.box-body -->
            </div>
        </div>
    </div>
</section>

<script>
function toggleBreakdown() {
    var viewMode = document.getElementById("view_mode").value;
    var classFilter = document.getElementById("class_filter");
    var levelFilter = document.getElementById("level_filter");
    if (viewMode === "broken") {
        classFilter.style.display = "block";
        levelFilter.style.display = "block";
    } else {
        classFilter.style.display = "none";
        levelFilter.style.display = "none";
    }
}
</script>
