      <link href="<?php echo base_url(); ?>assets/vendors/datatables.net-bs/css/dataTables.bootstrap.min.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons-bs/css/buttons.bootstrap.min.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/vendors/datatables.net-fixedheader-bs/css/fixedHeader.bootstrap.min.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/vendors/datatables.net-responsive-bs/css/responsive.bootstrap.min.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/vendors/datatables.net-scroller-bs/css/scroller.bootstrap.min.css" rel="stylesheet">
    
        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
                <div class="title_left">
                    <h3>Head Level 2</h3>
                </div>
            </div>
            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-6 col-sm-6 col-xs-6">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Add Head level 2</h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a></li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">

                    <form class="form-horizontal form-label-left" action="<?php echo base_url(); ?>account/SaveLevels" method="post">
              
                        <input type="hidden" name="id" <?php if($edit['id']!==null){ echo "value='".$edit['id']."'";}else {echo "value=''";} ?> />
                       
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Main Head<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <select  name="main_head" id="main_head" class="form-control" required>
                              <option value="">Select Main Head</option>
                              <?php
                              foreach ($head as $value) {
                                ?>
                                <option <?php if($value['id']==$edit['parent_id']){echo "selected";} ?>  value="<?php echo $value['id'];?>"><?php echo $value['name'];?></option>  
                                <?php
                              }  
                              ?>
                            </select>

                        </div>
                      </div>

                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Name <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        <input name="name" id="name" <?php if($edit!=null){echo "value='".$edit['name']."'";}?> placeholder="Level 2 Name..." class="form-control abc12" maxlength="30" required>                    
                        </div>
                      </div>    
                       
                        <input type="hidden" name="opbalance" value="0"   class="form-control " >                    
                        <input type="hidden" name="cr/dr" value="null"   class="form-control " >                    
                        
                     
                      <input type="hidden" name="type" value="level2">
                      
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                          <button id="send" type="submit" class="btn btn-success pull-right">Add</button>
                        </div>
                      </div>
                    </form>
                  </div>
                </div>
             
              </div>
                <div class="col-md-6 col-sm-6 col-xs-6">
                <div class="x_panel">
                  <div class="x_title">
                    <h2> Level 2 View</h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  
                  <div class="x_content table-responsive" style="overflow-y:scroll" >
                    <table id="datatable1" class="table table-striped table-bordered" style="width:100%">
                      <thead>
                        <tr>
                          <th>#</th>
                          <th style="width:100px;">Main Head</th>
                          <th style="width:100px;">Name</th>
                          <th style="width:100px;">Opening Balance</th>
                          <th style="width:100px;">Dr/Cr</th>
                          <th>Actions</th>
                        </tr>
                      </thead>

                      
                      <tbody class="center">
                        <?php foreach ($View as $key => $value) {
                           $level = 2;
                           $val2 = $value['level_'.($level)];
                           if(@$value['level_'.$level]){
                           foreach($val2 as $key3 => $vv) {
                        ?>
                          <tr>
                          <td><?php echo ++$key ?></td>
                          <td><?php echo $value['name'] ?></td>
                          <td><?php echo $vv['name']; ?></td>
                          <td><?php echo $vv['opbalance']; ?></td>
                          <td><?php echo $vv['cr_dr']; ?></td>
                          <td><a href="<?php echo base_url(); ?>account/level2/<?php echo $vv['id']; ?>/l2"><i class="fa fa-edit"></i></a>  <a href="<?php echo base_url(); ?>account/delete_level/<?php echo $vv['id']; ?>"><i class="fa fa-trash"></i></a></td>
                          </tr>                           <?php  } }
                        } ?>
                        
                      

                      </tbody>

                    </table>
                   
                  </div>
                </div>
              </div>
             
              </div>
            
               <div class='row'>
              <div class="col-md-6 col-sm-6 col-xs-6">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Level 2 Assign</h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">
                   <form class="form-horizontal form-label-left" action="<?php echo base_url(); ?>account/save_assining" method="post">
                   <input type="hidden" name="id" <?php if($edit1!=null){echo "value='".$edit1['id']."'";}else{echo "value='0'";} ?>>
                   <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Branch <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select id="branch" class="form-control col-md-7 col-xs-12" name="branch" required="required">
                            

                            <option value=''>Select Branch</option>
                    <?php       
                              foreach ($branch as $value) {?>
                    <option value="<?php echo $value['id']; ?>" <?php if($edit1['branch']==$value['id']){echo "selected";} ?>><?php echo $value['name']?></option>

                  <?php } ?>
                          </select>
                        </div>
                      </div>
                       <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Main Head <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select id="main_head1" class="form-control col-md-7 col-xs-12" name="main_head" required="required">
                            

                            <option value=''>Select Main Head</option>
                    <?php       
                              foreach ($head as $value) {?>
                    <option value="<?php echo $value['id']; ?>" <?php if($edit1['main_head']==$value['id']){echo "selected";} ?>><?php echo $value['name']?></option>

                  <?php } ?>
                          </select>
                        </div>
                      </div>
                      
                      <?php if($edit1!=null){ ?>
                   <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Level 2 <span class="required">*</span>
                        </label>
                       
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select id="level2" class="form-control col-md-7 col-xs-12" name="level2" required="required">
                            

                            <option value=''>Select Level 2</option>
                             <?php       
                              foreach ($level2 as $value) {?>
                    <option value="<?php echo $value['id']; ?>" <?php if($edit1['level2']==$value['id']){echo "selected";} ?>><?php echo $value['name']?></option>

                  <?php } ?>
                     </select>
                        </div>
                      </div><?php }else{ ?>
                         <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Level 2 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select id="level2" class="form-control col-md-7 col-xs-12" name="level2" required="required">
                            

                            <option value=''>Select Level 2</option>
                     </select>
                        </div>
                        <span id="error" class="text-danger"></span>
                      </div>
                      <?php } ?>
                      <input type="hidden" id="prog" name="prog"  value="0"> 
                      <input type="hidden" id="pro" name="pro"  value="0">
                   <input type="hidden" id="l3" name="level3"  value="0">  
                   <input type="hidden" id="l4" name="level4"  value="0">  
                   <input type="hidden" id="l5" name="level5"  value="0">  
                   <input type="hidden" id="bank" name="bank"  value="0"> 
                   <input type="hidden" name="type"  value="level2">   
                   <input type="hidden" name="link"  value="account/level2">
  
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                          <button id="send" type="submit" class="btn btn-success pull-right send">Assign</button>
                        </div>
                      </div>
                    </form> 
                  
                  </div>
                </div>
              </div>
               <div class="col-md-6 col-sm-6 col-xs-6">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Level 2 Assign View</h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content" style="overflow-y:scroll">
                    <table id="datatable2" class="table table-striped table-bordered " style="width:100%">
                      <thead>
                        <tr>
                          <th>#</th>
                          <th style="width:100px;">Branch</th>
                          <th style="width:100px;">Main Head</th>
                          <th style="width:100px;">Level 2</th>
                          <th style="width:100px;">Actions</th>
                        </tr>
                      </thead>


                      <tbody  id="center">
                      <?php foreach ($assign as $key => $value) {  $bname=$this->account_model->SearchId("branch",$value['branch']);   
                     $headname=$this->account_model->SearchId("head",$value['main_head']);   
                     $l2name=$this->account_model->SearchId("head",$value['level2']);
                    
                     
                     ?>
                       
                     <tr>
                     <td><?php echo ++$key; ?></td>
                     <td><?php echo  $bname;  ?></td>
                     <td><?php echo $headname;  ?></td>
                     <td><?php echo $l2name;  ?></td>
                     
                   
                     
                     <td><a href="<?php echo base_url(); ?>account/level2/<?php echo $value['id']; ?>/assign"><i class="fa fa-edit"> </i></a> <a href="<?php echo base_url(); ?>account/delete_assign/level2/<?php echo $value['id']; ?>"><i class="fa fa-trash"></i></a></td>
                     </tr>
                     <?php  } ?>
                        
                      

                      </tbody>

                    </table>
                  
                  </div>
                </div>
              </div>
</div> 
            
            
            
            
            </div>
          
          </div>
                  <!-- /page content -->
        <script src="<?php echo base_url(); ?>assets/vendors/jquery/dist/jquery.min.js"></script>
        <script src="<?php echo base_url(); ?>assets/vendors/datatables.net/js/jquery.dataTables.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/buttons.flash.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/buttons.html5.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-buttons/js/buttons.print.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/datatables.net-scroller/js/datatables.scroller.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/jszip/dist/jszip.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/pdfmake/build/pdfmake.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/pdfmake/build/vfs_fonts.js"></script>
    <script>
        $(document).ready(function() {
        
        $('#datatable1').DataTable(
            {
            "bPaginate":true,
            "bFilter":true,
            "bInfo":false,
            "ordering":false,
            "scrollX":true,
            dom: 'Bfrtip',
            buttons: [
            'csv', 'pdf',{extend:'excel',text:'Excel',exportOptions:{columns:[0,1,2,3,4]}}            ]
            }
        );

        $('#datatable2').DataTable(
            {
            "bPaginate":true,
            "bFilter":true,
            "bInfo":false,
            "ordering":false,
            "scrollX":true,
            dom: 'Bfrtip',
            buttons: [
            'csv', 'pdf',{extend:'excel',text:'Excel',exportOptions:{columns:[0,1,2,3]}}            ]
            }
        );
       
        });
        
        </script>
      <script>
        $('#main_head').change(function(){
          var id=$('#main_head').val();
         
         
       $("tbody.center" ).empty();
          $.ajax({
                    url: "<?php echo base_url(); ?>Load_account/HeadAgainstLevel2View/"+id,
                    data: {},
                      success: function( result ) {
                          $( "tbody.center" ).html(result);
  }
});

        });
        $('#main_head1').change(function(){
          var id=$(this).val();
          $.ajax({
                    url: "<?php echo base_url(); ?>Load_account/level2_db/"+id,
                    data: {},
                      success: function( d ) {
                         var pre='<option value="">Select Level 2</option>';
                         
                         
                          $( "#level2" ).html(pre+d);
  }
});

          var b=$('#branch').val();
          
            $("tbody#center" ).empty();
          $.ajax({
                    url: "<?php echo base_url(); ?>Load_account/level2assign_View/"+id+"/"+b,
                    data: {},
                      success: function( d ) {
                        
                        $( "tbody#center" ).html(d);
  }
});

        });
        
           $('#level2').change(function(){
        var bid=$('#branch').val();
        var prog=$('#prog').val();
        var proj=$('#pro').val();
        var main=$('#main_head1').val();
        var l2=$('#level2').val();
        var l3=$('#l3').val();
        var l4=$('#l4').val();
        var l5=$('#l5').val();
        var bank=$('#bank').val();
        var val={'branch':bid,'prog':prog,'proj':proj,'main':main,'l2':l2,'l3':l3,'l4':l4,'l5':l5,'bank':bank};
         
       $.ajax({
                    url: "<?php echo base_url(); ?>Load_account/check_assigning/",
                    type:'post',
                    data:val,
                    success: function( d ) {
                     console.log(d);
                       if(d==1){
                         $('#error').html('Already Assigned');
                         $('.send').prop("disabled",true);
                       }else{
                         $('#error').html(' ');
                         $('.send').prop("disabled",false);
                       }
                          
  }
});
      });

        
  
         
        </script>   
