<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('issues,receipts,warehousetransfers'); ?>
                    </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/invoiced_vs_received'); ?>" method="post" class="form-horizontal">
                                <?php echo $this->customlib->getCSRF(); ?> 
                                
                                <div class="form-group">
                                    <!-- Inventory Item Filter -->
                                    <div class="col-sm-4">
                                        <label>Inventory Item</label>
                                        <select id="inventory_item" name="inventory_item" class="form-control" onchange="toggleItemFilter()">
                                            <option value="">-- Select Item Type --</option>
                                            <option value="uniform" <?= (isset($inventory_item) && $inventory_item == 'uniform') ? 'selected' : '' ?>>Uniform</option>
                                            <option value="other" <?= (isset($inventory_item) && $inventory_item == 'other') ? 'selected' : '' ?>>Other Inventory Items</option>
                                        </select>
                                    </div>

                                    <!-- Select Item filter (only for 'Other') -->
                                    <div class="col-sm-4" id="itemFilter" style="display:none;">
                                        <label>Select Item</label>
                                        <select name="item_id" class="form-control">
                                            <option value="">-- Select Item --</option>
                                            <?php if (!empty($itemcatlist)) { ?>
                                                <?php foreach ($itemcatlist as $item) { ?>
                                                    <option value="<?php echo $item['id']; ?>" 
                                                        <?= (isset($item_id) && $item_id == $item['id']) ? 'selected' : '' ?>>
                                                        <?php echo $item['item_category']; ?>
                                                    </option>
                                                <?php } ?>
                                            <?php } ?>
                                        </select>
                                    </div>

                                    <div class="col-sm-4">
                                        <label><?php echo $this->lang->line('date_from'); ?></label>
                                        <input autofocus id="datefrom" name="date_from" type="text" class="form-control date"  
                                               value="<?php echo set_value('date_from'); ?>" />
                                        <span class="text-danger"><?php echo form_error('class_id'); ?></span>
                                    </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'); ?>" />
                                    </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 checkbox-toggle pull-right">
                                            <i class="fa fa-search"></i> <?php echo $this->lang->line('search'); ?>
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>

                    <!-- Table Section -->
                    <?php if (!empty($item_issues)) { ?>
                        <div class="box-body table-responsive">
                            <table class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>Issue Date</th>
                                        <th>Issue By</th>
                                        <th>Issue From</th>
                                        <th>Issue To</th>
                                        <th>Received By</th>
                                        <th>Quantity</th>
                                        <th>Item Category</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($item_issues as $row) { ?>
                                        <tr>
                                            <td><?php echo $row->id; ?></td>
                                            <td><?php echo $row->issue_date; ?></td>
                                            <td><?php echo $row->issue_by; ?></td>
                                            <td><?php echo $row->issue_from; ?></td>
                                            <td><?php echo $row->issue_to; ?></td>
                                            <td><?php echo $row->received_by; ?></td>
                                            <td><?php echo $row->quantity; ?></td>
                                            <td><?php echo $row->item_category; ?></td>
                                        </tr>
                                    <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    <?php } else { ?>
                        <p class="text-center">No records found.</p>
                    <?php } ?>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- JS to toggle item filter -->
<script>
function toggleItemFilter() {
    var inventoryType = document.getElementById("inventory_item").value;
    var itemFilter = document.getElementById("itemFilter");
    if (inventoryType === "other") {
        itemFilter.style.display = "block";
    } else {
        itemFilter.style.display = "none";
    }
}
// Run on page load (to keep state after post)
toggleItemFilter();

// Datepicker initialization
$(function() {
    $('.date').datepicker({
        autoclose: true,
        todayHighlight: true,
        format: 'yyyy-mm-dd'
    });
});
</script>
