<div class="content-wrapper" style="min-height: 946px;">
    <section class="content-header">
        <h1>
            <i class="fa fa-line-chart"></i> Cashbook <?php echo $this->lang->line('reports'); ?> <small> <?php echo $this->lang->line('filter_by_name1'); ?></small></h1>
    </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-search"></i> <?php echo $this->lang->line('select_criteria'); ?></h3>
                    </div>
                    <form role="form" action="<?php echo site_url('cashbook/cashbooksearch') ?>" method="post" class="">
                        <div class="box-body row">

                            <?php echo $this->customlib->getCSRF(); ?>

                            <div class="col-sm-8 col-md-4">
                                <div class="form-group">
                                    <label for="cashbook">Cashbook Account</label><small class="req"> *</small>
										<select id="cashbook" name="cashbook" placeholder="" type="text" class="form-control" >
											<option value="select"><?php echo $this->lang->line('select') ?></option>
											<?php 
												foreach ($cashbook->result() as $grup) {
												?>
									                <option value="<?php echo $grup->cashbook_accounts; ?>" >  <?php echo $grup->cashbook_accounts; ?></option>
											<?php }
											?>
										</select>
                                    <span class="text-danger"><?php echo form_error('cashbook'); ?></span>
                                </div> 
                            </div>                           
							<div class="col-sm-8 col-md-4">
								<div class="form-group">
									<label for="colour">From Date</label><small class="req"> *</small>
									<input autofocus="" id="from" name="from" placeholder="" type="date" class="form-control"  value="<?php echo set_value('from'); ?>" />
									<span class="text-danger"><?php echo form_error('from'); ?></span>
								</div>
                            </div>                             
							<div class="col-sm-8 col-md-4">
								<div class="form-group">
									<label for="colour">Receipt</label><small class="req"> *</small>
									<input autofocus="" id="to" name="to" placeholder="" type="date" class="form-control"  value="<?php echo set_value('to'); ?>" />
									<span class="text-danger"><?php echo form_error('to'); ?></span>
								</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>
            <?php
            if (isset($resultlist)) {
                ?>
                <div class="box box-info" style="padding:5px;">
                    <div class="box-header ptbnull">
                        <h3 class="box-title titlefix"><i class="fa fa-users"></i> Cashbook Report</h3>
                    </div>
                    <div class="box-body table-responsive">
					<div class="download_label">Cashbook Report</div>
                       	<table class="table table-striped table-bordered table-hover example">
                                <thead>
                                    <tr>
                                        <th>Date Captured</th>
                                        <th>Cashbook</th>
                                        <th>Reference (Receipt)</th>
                                        <th>Currency</th>
                                        <th>Debit</th>
                                        <th>Credit</th>
                                        <th>Balance</th>
                                       
                                    </tr>
                                </thead>
                                <tbody>
                                <?php  
																
										 foreach ($cashresultlist->result() as $row)  
										 {   
                                        ?>
                                        <tr>
                                            <td class="mailbox-name"><?php echo $row->date_captured;?></td>
                                            <td class="mailbox-name"><?php echo $row->cashbook;?></td>
                                            <td class="mailbox-name"><?php echo $row->receipt;?></td>
                                            <td class="mailbox-name"><?php echo $row->currency;?></td>
                                            <td class="mailbox-name"><?php echo $row->debit;?></td>
                                            <td class="mailbox-name"><?php echo $row->credit;?></td>                                        
                                            <td class="mailbox-name"><?php echo $row->balance;?></td>                                        
                                        </tr>
									<?php } ?>
                                </tbody>
                            </table><!-- /.table -->

                    </div>
                </div>
                <?php
            }
            ?>
        </div>       
</div>  
</section>
</div>

<script type="text/javascript">
    function getSectionByClass(class_id, section_id) {
        if (class_id != "" && section_id != "") {
            $('#section_id').html("");
            var base_url = '<?php echo base_url() ?>';
            var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
            $.ajax({
                type: "GET",
                url: base_url + "sections/getByClass",
                data: {'class_id': class_id},
                dataType: "json",
                success: function (data) {
                    $.each(data, function (i, obj)
                    {
                        var sel = "";
                        if (section_id == obj.section_id) {
                            sel = "selected";
                        }
                        div_data += "<option value=" + obj.section_id + " " + sel + ">" + obj.section + "</option>";
                    });
                    $('#section_id').append(div_data);
                }
            });
        }
    }

    $(document).ready(function () {
        var class_id = $('#class_id').val();
        var section_id = '<?php echo set_value('section_id') ?>';
        getSectionByClass(class_id, section_id);
        $(document).on('change', '#class_id', function (e) {
            $('#section_id').html("");
            var class_id = $(this).val();
            var base_url = '<?php echo base_url() ?>';
            var div_data = '<option value=""><?php echo $this->lang->line('select'); ?></option>';
            $.ajax({
                type: "GET",
                url: base_url + "sections/getByClass",
                data: {'class_id': class_id},
                dataType: "json",
                success: function (data) {
                    $.each(data, function (i, obj)
                    {
                        div_data += "<option value=" + obj.section_id + ">" + obj.section + "</option>";
                    });
                    $('#section_id').append(div_data);
                }
            });
        });
    });
</script>