<aside class="right-side">
    <section class="content-header">
        <div class="title_bar">
            <h1 class="major_txt_color"><?php echo $title;?></h1>
            <div class="breadcrumb_container"><?php echo breadcrumb_links();?></div>
        </div>
    </section>
    <?php $general = get_general_setting();?>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <!-- /.box -->
                <div class="box box-primary">
                    <div class="box-body table-responsive">
                        <form name="get_data_search" action="<?php echo $form_action;?>" method="post" class="search_form validate_form">
                            <input type="hidden" name="hidden_id" class="hidden_id" value="<?php echo (!empty($hidden_id)) ? $hidden_id : '';?>" />
                            
                            <!-- Filtered Columns to send JS - Start -->
                            <input type="hidden" name="hidden_print" class="hidden_print" value="<?php echo (!empty($start_date)) ? 1 : 0 ;?>" />
                            <?php foreach($filters as $key=>$val) : ?>
                                <input type="hidden" name="hidden_filter_array[]" class="hidden_filter_array" value="<?php echo $val;?>" />
                            <?php endforeach;?>
                            <!-- Filtered Columns to send JS - End -->
                            
                            <div class="col-xs-12">
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label >Category Name</label>
                                        <div class="input-group">
                                            <div class="input-group-addon">
                                                <i class="fa fa-soccer-ball-o"></i>
                                            </div>
                                            <select name="cat_id" class="form-control select2">
                                                <option value="">Select Category</option>
                                                <?php foreach($categories as $key=>$row) {?>
                                                    <option value="<?php echo $row->id;?>" <?php echo ($row->id == $cat_id) ? 'selected' : '';?>><?php echo $row->cat_name;?></option>
                                                <?php } ?>
                                            </select>
                                        </div>    
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label >Item Name</label>
                                        <div class="input-group">
                                            <div class="input-group-addon">
                                                <i class="fa fa-soccer-ball-o"></i>
                                            </div>
                                            <select name="item_id" class="form-control select2">
                                                <option value="">Select Item</option>
                                                <?php foreach($items as $key=>$row) {?>
                                                    <option value="<?php echo $row->id;?>" <?php echo ($row->id == $item_id) ? 'selected' : '';?>><?php echo $row->item_name.'&nbsp;/&nbsp;'.$row->item_code;?></option>
                                                <?php } ?>
                                            </select>
                                        </div>    
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label >Start Date</label>
                                        <div class="input-group">
                                            
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="start_date" placeholder="DD-MM-YYYY" style="padding: 6px 12px;margin-right:5%;width:100%;" id="start_date" name="start_date" value="<?php echo (!empty($start_date)) ? $start_date : date('d-m-Y');?>" autocomplete="off" >
                                            
                                        </div>
                                    </div>
                                    
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label >End Date</label>
                                        <div class="input-group">
                                            
                                            <div class="input-group-addon">
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" class="end_date" placeholder="DD-MM-YYYY" style="padding: 6px 12px;margin-right:5%;width:100%;"  id="end_date" name="end_date" value="<?php echo (!empty($end_date)) ? $end_date : date('d-m-Y');?>" autocomplete="off" >
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-xs-12">
                                <div class="col-md-5">&nbsp;</div>
                                <div class="col-md-4">
                                    <input type="submit" value="Get Data" name="submit" class="btn btn-danger btn-sm" style="background-color: #e33739;
    border-color: #e33739;" />&nbsp;&nbsp;
                                
                                    <input type="submit" value="Print Data" name="submit" class="btn btn-primary btn-sm" />
                                </div>
                                <div class="col-md-2">&nbsp;</div>
                            </div>
                            
                            <!-- Filtered Columns to send JS - Start -->
                            <div class="col-xs-12" style="margin-bottom:4%;">
                                <div class="col-xs-12 blck" style="margin-bottom: -35px;">
                                    <div class="sub-title" style="color:#0B45B3; background:#f3f3f3 !important;" ><h4><i class="fa fa-fire" style="font-size: 14px;"></i> Filter Columns</h4><i class="ctrl opener opened fa fa-chevron-up" style="float: right; margin-top: -25px;"></i></div>
                                    <div class="blck-content col-xs-12" style="border-bottom: 1px inset rgba(209, 216, 216, 0.6); background: rgba(3, 12, 11, 0.05); margin-top: -15px;">
                                        <div id="grpChkBox" class="grpChkBox">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- Filtered Columns to send JS - End -->
                            
                        </form>
                    </div>
                    <div class="box-body table-responsive">
                        <table class="table table-bordered table-striped data_table filterTable" id="filterTable">
                            <thead>
                                <tr>
                                    <th width="5%" class="align-center">S.No</th>
                                    <th class="align-center">Ref No</th>
                                    <th class="align-center">Category Name</th>
                                    <th class="align-center">Item Name</th>
                                    <th class="align-center">Invoice No</th>
                                    <th class="align-center">Invoice Date</th>
                                    <th class="align-center">Vendor Name</th>
                                    <th class="align-center">Ship Advice No</th>
                                    <th class="align-center">Received Date</th>
                                    <th class="align-center">Box No</th>
                                    <th class="align-center">Description</th>
                                    <th class="align-center">Quantity</th>
                                    <th class="align-center">Cost per Item</th>
                                    <th class="align-center">Amount</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if(count($results) > 0) { ?>
                                    <?php foreach($results as $key=>$value) {?>
                                        <tr>
                                            <td class="align-center"><?php echo ++$key;?></td>
                                            <td><?php echo text($value->code);?></td>
                                            <td><?php echo text($value->cat_name);?></td>
                                            <td><?php echo text($value->item_name);?></td>
                                            <td><?php echo text($value->invoice_no);?></td>
                                            <td><?php echo ($value->invoice_date != '1970-00-00 00:00:00') ? date('d-m-Y',strtotime($value->invoice_date)) : 'N/A';?></td>
                                            <td><?php echo text($value->vendor);?></td>
                                            <td><?php echo text($value->ship_advice_no);?></td>
                                            <td><?php echo ($value->received_date != '1970-00-00 00:00:00') ? date('d-m-Y',strtotime($value->received_date)) : 'N/A';?></td>
                                            <td><?php echo text($value->box_no);?></td>
                                            <td><?php echo text(nl2br($value->description));?></td>
                                            <td class="align-center"><?php echo text($value->quantity);?></td>
                                            <td class="align-right"><?php echo $value->cost_per_item;?></td>
                                            <td class="align-right"><?php echo $value->total_amount;?></td>
                                        </tr>
                                    <?php } ?>
                                <?php } ?>
                            </tbody>
                            <tfoot>
                            </tfoot>
                        </table>
                    </div><!-- /.box-body -->
                </div><!-- /.box -->
            </div>
        </div>
    </section><!-- /.content -->
</aside><!-- /.right-side -->
<!-- ./wrapper -->

<script type="text/javascript">
    $(document).ready(function() {
        $('.start_date').bootstrapMaterialDatePicker({ 
            time: false, 
            format: 'DD-MM-YYYY'
        }). on('change', function(e, date) {
            if($('.end_date').val() != '') {
                $('.end_date').val('');
                var cur_date = new Date(date);
                $('.end_date').val(getTwoDigits(cur_date.getDate()) + '-'+ getTwoDigits((cur_date.getMonth() + 1)) + '-'+ cur_date.getFullYear());
                change_todate(getTwoDigits(cur_date.getDate()) + '-'+ getTwoDigits((cur_date.getMonth() + 1)) + '-'+ cur_date.getFullYear());
            }
        });
        
        $('.end_date').bootstrapMaterialDatePicker({ 
            time: false, 
            format: 'DD-MM-YYYY'
        });
        
        var date = $('.start_date').val();
        change_todate(date);
     
        $('select[name="cat_id"]').change(function() {
            get_item_data();    
        });
    });
    function change_todate(date) {
       $('.end_date').bootstrapMaterialDatePicker('setMinDate', date);
    }
    
    function get_item_data() {
        var cat_id = $('select[name="cat_id"]').val();
        $.ajax({
            async: false,
            url:  base_url + 'statue_books_purchase_report/get_item_by_cat_id',
            type: 'POST',
            data: {
                cat_id: cat_id
            },
            dataType: "json"
        })
        .done(function(data) { 
            var item_data ='';
            item_data += '<option value="">Select Item</option>';
            for(var i in data.items) {
                var dataItem = data.items[i];
                item_data += '<option value="'+ dataItem.id +'">' + dataItem.item_name + ' / '+ dataItem.item_code + '</option>';
            }
            $('select[name="item_id"]').html(item_data);
        })
        .fail(function(XHR, status_code, error_thrown) {
            console.log(error_thrown);
        });
    }
</script>