<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="ledger_search" name="ledger_search" action="<?php echo base_url();?>General_masters/ledger" method="get">
    <div class="row">
        <div class="col-md-5">
            <div class="form-group">
                <label>Ledger Group Name</label>
				
                 <select class="form-control" id="ledger_group_id" name="ledger_group_id">
                </select>
            </div>
            <!-- /.form-group -->
        </div>
        <!-- /.col -->
        <div class="col-md-5">
            <div class="form-group">
                <label>Ledger Name</label>
                <select class="form-control " id="ledger_master_id" name="ledger_master_id">
                     
                </select>
            </div>
            <!-- /.form-group -->
        </div>
        <!-- /.col -->
        <div class="col-md-2">
            <div class="form-group">
              	<button class="btn btn-block btn-warning"><b>Search</b></button>
              	<a href="<?php echo base_url();?>General_masters/add_ledger" class="btn btn-block btn-info"><b>New Ledger</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>Ledger Name</th>
                <th>Ledger Group Name</th>
				<th>Company </th>
				<th>Branch </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['ledger_name'];?></td>
	    			<td><?php  echo $row['parent'];?></td>
					<td><?php  echo $row['companyname'];?></td>
				    <td><?php  echo $row['branch_name'];?></td>
	    		
	    			<td><a href="<?php echo base_url();?>General_masters/edit_ledger/<?php echo $row['ledger_master_id'];?>"><i class="fa fa-edit"></i></a></td>
	    		</tr>
        	<?php }
        }?>
        </tbody>
    </table>
</div>
 

<script type="text/javascript">
var parent_group = 0;
    $(function()
    {
        setTimeout(ledgergroup_select);
        setTimeout(ledger_select);
			
    });
    function ledgergroup_select()
    {
        $("#ledger_group_id").select2({
            ajax: { 
                dataType: 'json', 
                url: '<?php echo base_url();?>General_masters/get_ledgergroupsearch',
                cache: true,
                data: function (params) 
                    {
                        return {
                            q: params.term
                        }
                    }
            },
			initSelection: function(element, callback) {
			<?php if($ledger_group_id){ ?>
					callback({ 'id': <?php echo $ledger_group_id; ?>, 'text':'<?php echo $ledger_group_name; ?>' }) 
			<?php }else{ ?>
					callback({});
			<?php } ?>
			}
        })
    }
	
 $(document).on('change',"#ledger_group_id",function(){
 	parent_group = $(this).val();
 })	
	
 	
	
	  function ledger_select()
    {
          $("#ledger_master_id").select2({
		
            ajax: { 
                dataType: 'json', 
                 url: '<?php echo base_url();?>General_masters/get_ledgersearch',
                cache: true,
                data: function (params) 
                    {
                        return {
                            q: params.term,
							ledger_group_id:parent_group
                        }
                    }
            },
			initSelection: function(element, callback) {
			<?php if($ledger_master_id){ ?>
					callback({ 'id': <?php echo $ledger_master_id; ?>, 'text':'<?php echo $ledger_name; ?>' }) 
			<?php }else{ ?>
					callback({});
			<?php } ?>
			}
        })
    }
	 
</script>

