 <link href="<?php echo base_url(); ?>assets/vendors/select2/dist/css/select2.min.css" rel="stylesheet">
 <style>
     input[type="checkbox"][readonly] {
  pointer-events: none;
}
 </style>
 <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
                <div class="title_left">
                    <h3></h3>
                </div>
            </div>
            <div class="clearfix"></div>
<?php if ($this->session->flashdata('sucmsg')): ?>
<div class="alert alert-success">
<?php echo $this->session->flashdata('sucmsg'); ?>
</div>
<?php endif ?>

<?php if ($this->session->flashdata('errmsg')): ?>
<div class="alert alert-danger">
<?php echo $this->session->flashdata('errmsg'); ?>
</div>
<?php endif ?>

            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Chart of Accounts</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_super_per" method="post">
                      <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-4 col-sm-6 col-xs-12">
                          <select class="form-control" name="branch" id="branch" required>
                              <option value="">Select Branch</option>
                              <?php
                              foreach($branch as $key=>$value)
                              {?>
    <option 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-2 col-sm-3 col-xs-12" for="name"><span class="required"></span>
                        </label>
                        <div class="col-md-12 col-sm-6 col-xs-12">
                         <?php
                         if(!empty($heads))
                         {?>
                         <div class="row">
                         <div class="col-md-8" style="background-color:#f7f7f7; margin-top:10px;flat:left"></div>
                         <div class="col-md-4" style="margin-top:10px;flat:right">
                          <input type="checkbox" class="type_checkbox" id="all_check" name="all_check">All
                         </div>
                         </div>
                         <?php
                         foreach($heads as $key=>$val)
                             {?>
                <div class="row">
                        
                       <div class="col-md-8" style="background-color:#f7f7f7; margin-top:10px;flat:left">
                         <?php 
                         $fetch_parents_lev1=0;
                         $fetch_parents_lev2=0;
                         $fetch_parents_lev3=0;
                         $fetch_parents_lev4=0;
                         $fetch_parents_lev5=0;
                         $fetch_parents_lev6=0;
                         $fetch_parents_lev7=0;
                         if($val['parent'] !=0)
                         {
                             
                         $fetch_parents_lev1=$this->db->select('*')
                                                 ->from('account_heads')
                                                 ->where('id',$val['parent'])
                                                 ->get()->row();
                              $names[]=$fetch_parents_lev1->name;
                              $fetch_parents_lev1=$fetch_parents_lev1->parent;
                             // var_dump('<pre>',$fetch_parents_lev1);
                              //die();
                              if($fetch_parents_lev1!= 0)
                              {
                           $fetch_parents_lev2=$this->db->select('*')
                                                 ->from('account_heads')
                                              ->where('id',$fetch_parents_lev1)
                                                 ->get()->row();
                                 $names[]=$fetch_parents_lev2->name;
                                 $fetch_parents_lev2=$fetch_parents_lev2->parent;
                              }
                              if($fetch_parents_lev2!= 0)
                              {
                           $fetch_parents_lev3=$this->db->select('*')
                                                 ->from('account_heads')
                                              ->where('id',$fetch_parents_lev2)
                                                 ->get()->row();
                                 $names[]=$fetch_parents_lev3->name;        $fetch_parents_lev3=$fetch_parents_lev3->parent;     
                              }
                              
                            if($fetch_parents_lev3 != 0)
                              {
                           $fetch_parents_lev4=$this->db->select('*')
                                                 ->from('account_heads')
                                              ->where('id',$fetch_parents_lev3)
                                                 ->get()->row();
                                 $names[]=$fetch_parents_lev4->name;            $fetch_parents_lev4=$fetch_parents_lev4->parent;     
                              }
                              
                              if($fetch_parents_lev4 != 0)
                              {
                           $fetch_parents_lev5=$this->db->select('*')
                                                 ->from('account_heads')
                                              ->where('id',$fetch_parents_lev4)
                                                 ->get()->row();
                                 $names[]=$fetch_parents_lev5->name;            $fetch_parents_lev5=$fetch_parents_lev5->parent;     
                              }
                              
                              if($fetch_parents_lev5 != 0)
                              {
                           $fetch_parents_lev6=$this->db->select('*')
                                                 ->from('account_heads')
                                              ->where('id',$fetch_parents_lev5)
                                                 ->get()->row();
                                 $names[]=$fetch_parents_lev6->name;            $fetch_parents_lev6=$fetch_parents_lev6->parent;     
                              }
                              
                               if($fetch_parents_lev6 != 0)
                              {
                           $fetch_parents_lev7=$this->db->select('*')
                                                 ->from('account_heads')
                                              ->where('id',$fetch_parents_lev6)
                                                 ->get()->row();
                                 $names[]=$fetch_parents_lev7->name;                 
                              }
                            
                             $names= array_reverse($names);
                             // var_dump($names);
                             // die();
                             if(!empty($names)){
                                 $i=1;
                                 $cod=$this->db->select('code')
                                                   ->from('account_heads')
                                                   ->where('id',$val['id'])
                                                   ->get()->row_array()['code'];
                                     echo "<b>".$cod."</b>"."   "; 
                                 foreach($names as $key=>$valtm)
                                 {
                                     
                                     echo " "."<b>".$valtm."</b>";
                                    
                                     $i++;
                                 }
                                 unset($names); 
                             }
                         }
                         ?>
                       </div> 
                       
                       <div class="col-md-4" style="margin-top:10px;flat:right">
                       <?php
                       if($val['id']==6 || $val['id']==7)
                       {?>
                         <input type="checkbox" class="type_checkbox" name="checkme[]" value="<?php echo $val['id'];?>" checked readonly>  
                      <?php }else
                      {
                       ?>
                       <input type="checkbox" class="type_checkbox" name="checkme[]" value="<?php echo $val['id'];?>" checked> 
                       <?php } ?>
                       <?php echo $val['name'];?>
                       </div> 
                       
                </div>
                           
                        <?php
                          }
                             
                         }
                          ?>
                        </div>
                      </div>
                      
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-4 col-md-offset-2">
                          <button id="send" type="submit" class="btn btn-success pull-right">Save</button>
                        </div>
                      </div>
                    </form>
                  </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/jquery/dist/jquery.min.js"></script>
        <script src="<?php echo base_url(); ?>assets/vendors/select2/dist/js/select2.full.min.js"></script>
        <!-- Select2 -->
        <script src="<?php echo base_url(); ?>assets/vendors/select2/dist/js/select2.min.js"></script>
                <script>
window.setTimeout(function() {
$(".alert").fadeTo(500, 0).slideUp(500, function(){
    $(this).remove(); 
});
}, 3000);
        </script>
        <script>
            $("#branch").select2();
            $(document).ready(function(){
         var branch= $('#branch1').val();
        });
                   
        </script>
            <script>
        $(document).ready(function(){
            $(document).on("change","#branch",function(){
                var value = $(this).val();
                  $.get("<?php echo base_url(); ?>account/check_per/"+value,{},function(d){
                   data = JSON.parse(d);
                          
        $("input[name='checkme[]']").each(function () {
            var slt_vl=$(this).val();
            if(slt_vl ==6 || slt_vl ==7)
            {
             $(this).prop('checked',true);
            }else
            {
               $(this).removeAttr('checked');  
            }
            //new
            
          if(data!=""){
          $.each( data, function( key, value ) {
          if(slt_vl == value.head){
            $('input.type_checkbox[value="'+value.head+'"]').prop('checked', true);
                 }
               });
            }
            
            //end
        });
                    });
               
            });
            
        });
    </script>
    <script>
    $(document).ready(function() {
   
    $('#all_check').change(function() {
        if($(this).is(":checked")) {
           $("input[name='checkme[]']").each(function () {
            
            $(this).prop('checked',true);
           
        });
        }else
        {
         $("input[name='checkme[]']").each(function () {
         var slt_vl=$(this).val();
            if(slt_vl ==6 || slt_vl ==7)
            {
             $(this).prop('checked',true);
            }else
            {
               $(this).removeAttr('checked');  
            }
             });
            
        }//else
    });
});
    </script>
    