<?php
if($_GET)
{
    
    $branch_id      =   $_GET['branch_id'];
}
else
{
    
    $branch_id      =   '';
}
?>
<div style="color:green;text-align:center" class="success"><strong><?php if($this->session->flashdata('msg')){ echo $this->session->flashdata('msg');} ?></strong></div>
<div class="box-body">
	<form role="form" id="branch_search" name="branch_search" action="<?php echo base_url();?>General_masters/branch" method="get">
    <div class="row">
      
        <div class="col-md-5">
            <div class="form-group">
                <label>Branch</label>
                <select class="form-control select2" id="branch_id" name="branch_id">
                    <option value="">Select Branch</option>
                    <?php foreach($branch_drpdwn as $row)
                    {?>
                        <option value="<?php echo $row['branch_id'];?>" <?php if($row['branch_id']==$branch_id)echo "selected";?>><?php echo $row['branch_name'];?></option>
                    <?php }?>
                </select>
            </div>
            <!-- /.form-group -->
        </div>
        <div class="col-md-3">
        </div>
        <div class="col-md-2">
        <button class="btn btn-block btn-warning"><b>Search</b></button>
        </div>
        <!-- /.col -->
        <div class="col-md-2">
            <div class="form-group">
              	
              	<a href="<?php echo base_url();?>General_masters/add_branch" class="btn btn-block btn-info"><b>New Branch</b></a>
            </div>
            <!-- /.form-group -->
        </div>
        <!-- /.col -->
    </div>
    <!-- /.row -->
    </form>
</div>
<!-- /.box-header -->
<div class="box-body"> 
     <table id="example2" class="table table-bordered table-hover">
        <thead>
            <tr>
                <th style="width: 10px">#</th>
                <th>Name</th>
                <th>Place Of Loading</th>
                <th>Short Code</th>
                <th>Edit</th>
            </tr>
        </thead>
        <tbody>
        <?php $page_num=0;if(count($table_rows)!=0)
        {
        	$count	=	1;
        	foreach($table_rows as $row)
        	{?>
	    		<tr>
	    			<td><?php echo $count++;?></td>
	    			<td><?php echo $row['branch_name'];?></td>
	    			<td><?php echo $row['branch_pol'];?></td>
                    <td><?php echo $row['branch_shrt_code'];?></td>
	    			<td><a href="<?php echo base_url();?>General_masters/edit_branch/<?php echo $row['branch_id'];?>"><i class="fa fa-edit"></i></a></td>
	    		</tr>
        	<?php }
        }?>
        </tbody>
    </table>
</div>
<!-- /.box-body -->
<script type="text/javascript">
    $(function()
    {
        setTimeout(company_select);
        setTimeout(branch_select);
    });
    function company_select()
    {
        $("#branch_cmp_id").select2({
            ajax: { 
                dataType: 'json', 
                url: '<?php echo base_url();?>General_masters/get_company',
                cache: true,
                data: function (params) 
                    {
                        return {
                            q: params.term
                        }
                    }
            }
        });
    }
    function branch_select()
    {
        $("#branch_id").select2({
            ajax: { 
                dataType: 'json', 
                url: '<?php echo base_url();?>General_masters/get_branch',
                cache: true,
                data: function (params) 
                    {
                        return {
                            q: params.term,
                            company_id:$("#branch_cmp_id").val()
                        }
                    }
            }
        });
    }
</script>