          <link href="<?php echo base_url(); ?>assets/vendors/select2/dist/css/select2.min.css" rel="stylesheet">
        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
                <div class="title_left">
                    <h3>Cash Deposit</h3>
                </div>
            </div>
            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2>Add</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" <?php if(!empty($values)){ echo "action=".base_url()."account/print_bank"; }else{ echo  "action=".base_url()."account/SaveTransactions"; }  ?>  method="post">
                    
<?php $branch=$this->user_model->getbranch(); $name=$this->db->query("SELECT voucher_no FROM `trans` where type='Cash deposite' and branch=$branch order by voucher_no desc limit 1 ")->row_array()['voucher_no']; if($name==null){ $num=0; }else{
    preg_match_all('!\d+!', $name, $matches);
              $num=$matches[0][0];
} ?>
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Voucher #<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        <input name="voucher" readonly <?php  if($values['voucher_no']!=null){echo "value=".$values['voucher_no']."";} else{ echo "value='CD".++$num."'"; } ?>    class="form-control " maxlength="20" required>                   
                        </div>
                      </div> 
                      
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Date<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        <input name="date" <?php  if($values['date']!=null){echo "value=".$values['date']." disabled";} ?>  id="date" value="<?php echo date('Y-m-d') ?>" class="form-control date" maxlength="20" required>                    
                        </div>
                      </div>    
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Submit by<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        <input name="to"  id="to" <?php  if($values['name']!=null){echo "value='".$values['name']."' disabled";} ?> class="form-control abc" maxlength="50" required>                    
                        </div>
                      </div> 
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Description<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        <textarea name="description" <?php  if($values['description']!=null){echo "disabled";} ?>  id="des" class="form-control abc" maxlength="150"  required><?php if($values['description']!=null){echo $values['description'] ;} ?></textarea>                    
                        </div>
                      </div>
                      
                      
                      <?php  if($values['name']==null){ ?>
                      
                      <?php } ?>
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Slip #<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        <input name="cheque"   id="acno" <?php  if($values['cheque_no']!=null){echo "value=".$values['cheque_no']." disabled";} ?> class="form-control abc1" maxlength="20" required>                    
                        </div>
                      </div>
                      <?php if($values==null){ ?> 
                       <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" >Cash In Hand<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">

                     <input type="hidden" readonly name="bankid" value="0"  class="form-control">          
                     <input type="text" readonly  value="<?php echo  $this->account_model->search('head',80)['balance']; ?>" id="balance" class="form-control">          
                           
                        </div>
                      </div>
                      <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="pic">Slip Pic<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                     
                     <input type="file" name="pic">      
                        </div>
                      </div>
                       <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Programme<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                             <select name="prog"   class="form-control programme programme1 " required>
                              <option value="">Select program</option>
                              <?php
                              foreach ($pro as $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-3 col-sm-3 col-xs-12" for="name">Project<span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                              <select  name="proj"   class="form-control project project1" required>
                              <option  value="">Select Project</option>
                              
                            </select>           
                        </div>
                      </div>
                      
                      <?php } ?>
                        <?php if($values!=null){ ?> 
                          <table class="table table-striped">
                        <thead>
                        <tr>
                        <td>#</td><td>Progarmme</td><td>Project</td><td>Main Head</td><td>Level 2</td><td>Level 3</td><td>Level 4</td><td>Level 5</td><td>Amount</td>
                        </tr>
                        </thead>
                          <?php foreach ($viewentry as $key => $value) {
                           ?>
                           
                        <tbody>
                        <tr><td><?php echo ++$key; ?></td><td><?php echo $value['programme']; ?></td><td><?php echo $value['project']; ?></td>
                        <td><?php echo $value['main']; ?></td><td><?php echo $value['level2']; ?></td><td><?php echo $value['level3']; ?></td><td><?php echo $value['level4']; ?></td><td><?php echo $value['level5']; ?></td><td><?php echo $value['ammount']; ?></td></tr>
                        </tbody>
                        
                        
                          <?php } }else { ?>
                        <table class="table table-striped">
                        <thead>
                        <tr>
                        <td>#</td><td>Main Head</td><td>Level 2</td><td>Level 3</td><td>Level 4</td><td>Level 5</td><td>Amount</td>
                        </tr>
                        </thead>
                        <tbody>
                        <tr class="row_table row1">
                        <td>
                         <div class="form-control-static">
                        1
                      </div>
                      </td>
                      <td>
                      <select   data-id="1" readonly name="main"  class="form-control main main1" required>
                           <option value="">Select main Head</option>
                              
                            </select>   
                      </td>
                       <td>
                      <select readonly name="rec[1][level2]" data-id="1"  class="form-control level2 level21" required >
                              <option value="">Select Head Level 2</option>
                              
                            </select>
                      </td>
                       <td>
                      <select <?php  if($values['level_3_id']!=0){echo "disabled";} ?> readonly name="rec[1][level3]" data-id="1" id="level3" class="form-control level3 level31" required>
                              <option value="">Select Head Level 3</option>
                              
                            </select>
                      </td>
                       <td>
                      <select <?php  if($values['level4']!=0){echo "disabled";} ?> readonly name="rec[1][level4]" data-id="1"  class="form-control level4 level41" required>
                              <option value="">Select Head Level 4</option>
                              
                            </select>
                      </td>
                       <td>
                      <select <?php  if($values['level5']!=0){echo "disabled";} ?>  name="rec[1][level5]" data-id="1"  class="form-control select2_single level5 level51" required>
                              <option value="">Select Head Level 5</option>
                              <?php
                              foreach ($level5 as $value) {
                                ?>
                                <option value="<?php echo $value['id'];?>" data-pid="<?php echo $value['assignid']; ?>" ><?php echo $value['name'];?></option>  
                                <?php
                              }  
                              ?>
                            </select>
                      </td>
                       <td>
                     <input name="rec[1][amount]" data-id="1" type="number"   id="amount" class="form-control amount amount1" maxlength="20" required>
                      </td>
                                             <td style="font-size:18px" >RS:<span class="opbalance1"></span>/</td>
                      <td>
                      <button class="btn btn-primary removeRow" type="button" data-id="1">
                        <i class="fa fa-remove"></i>
                      </button>
                      </td>
                      </tr>
                        </tbody><?php } ?>
                      </table>
                      <div class="ln_solid"></div>
                      <div class="form-group">
                      <?php if($values==null){?>
                        <div class="col-md-6 col-md-offset-3">
                        <button type="button" class="btn btn-primary addRow pull-right add">
                    <i class="fa fa-plus" ></i>
                          <button id="send" type="submit" class="btn btn-success pull-right send">Add</button>
                           <input type="hidden" name="type" value="Cash deposite" >
                        </div>
                          </div>
                          </div>
                    </form>
                      <?php }else{ ?>
                     
                      <input type="hidden" name="id" value="<?php echo $values['id']; ?>" >
                      
                      <div class="col-md-6 col-md-offset-3">
                          <button id="submit" type="submit" class="btn btn-success pull-right ">Print</button>
                        </div>
                        </div>
                        
<?php }?>
                    
                  </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/select2/dist/js/select2.full.min.js"></script>
      <script>
      $(document).ready(function(){
         $('#ac_no').show();
      });

        $(document).on('change','.programme',function(){
          var val=$(this).val();
          
           
          $.ajax({
                    url: "<?php echo base_url(); ?>Load_account/proagainstproject/"+val,
                    data: {},
                      success: function( d ) {
                         var pre='<option value="">Select Project</option>';
                         
                          $( ".project1" ).html(pre+d);
  }
});

        });
           $(document).on('keyup','.amount',function(){
         var val = $(this).attr("data-id");
         view(val);
           
          
        }); 
      function view(val){
         
         var op = parseInt($('#balance').val());
         var id=Calculate();
         if(id<=op){
           
         var result=op-id;
         
         $('.opbalance'+val).html(result);
         $('.send').prop('disabled',false);
           $('.add').prop('disabled',false);
         }else{
           $('.send').prop('disabled',true);
           $('.add').prop('disabled',true);
         }
        }
function Calculate()
{
    var ammount = 0;
    $.each( $('.amount') , function(i,v){
        var val = $(v).val();
        if(val=="")
            val = 0;
      ammount += parseFloat( val );
    });
    return ammount;
}
       $('#bank').change(function(){
        var val=$("option:selected",this).attr("data-acountno");
        $('#ac_no').show();
        $('#acount_no').val(val);
         });

//         });
//         $(document).on('change','.level2',function(){
//           var id=$(this).val();
//            var val = $(this).attr("data-id");
//           $.ajax({
//                     url: "<?php echo base_url(); ?>Load_account/level3_assign/"+id,
//                     data: {},
//                       success: function( d ) {
//                          var pre='<option value="">Select Head Level 3</option>';
//                           $( ".level3"+val ).html(pre+d);
//   }
// });

//         });
//           $(document).on('change','.level3',function(){
//           var id=$(this).val();
//            var val = $(this).attr("data-id");
//           $.ajax({
//                     url: "<?php echo base_url(); ?>Load_account/level4_assign/"+id,
//                     data: {},
//                       success: function( d ) {
                        
//                          var pre='<option value="">Select Head Level 4</option>';
//                           $( ".level4"+val ).html(pre+d);
//   }
// });

        //});
         $(document).on('change','.level5',function(){
          var id = $('option:selected', this).attr('data-pid');
           var val = $(this).attr("data-id");
           console.log(val);
          $.ajax({
                    url: "<?php echo base_url(); ?>Load_account/level5againstallhead/"+id,
                    data: {},
                      success: function( d ) {
                         var re=JSON.parse(d);
                        var l4='<option value="'+re.level4_id+'" selected >'+re.level4_name+'</option>';
                        var l3='<option value="'+re.level3_id+'" selected >'+re["level3_name"]+'</option>';
                        var l2='<option value="'+re.level2_id+'" selected >'+re["level2_name"]+'</option>';
                        var main='<option value="'+re.main_id+'" selected >'+re["main_name"]+'</option>';
                        console.log(l4);
                          $('.main'+val).html(main);
                          $('.level2'+val).html(l2);
                          $('.level3'+val).html(l3);
                          $('.level4'+val).html(l4);
  }
});

        });
         

       
      $(document).ready(function(){
        var rows = 1;
      var wrapper = $("tbody");
      var row = '<tr class="row_table row{id}">'+
                '<td><div class="form-control-static">{id}</div></td>'+
                
                '<td>'+
                '<select   data-id="{id}" readonly name="main"  class="form-control main main{id}" required>'+
                           '<option value="">Select main Head</option>'+
                            '</select>'+
                '</td>'+
                '<td>'+
                  '<select name="rec[{id}][level2]" required="required" readonly class="form-control level2 level2{id}" data-id="{id}">'+
                    '<option value="">Select level2</option>'+
                  '</select>'+
                '</td>'+
                '<td>'+
                  '<select name="rec[{id}][level3]" required="required" readonly class="form-control level3 level3{id} " data-id="{id}">'+
                  '<option value="">Select level3</option>'+
                  '</select>'+
                '</td>'+
                '<td>'+
                  '<select name="rec[{id}][level4]" required="required" readonly class="form-control level4 level4{id}" data-id="{id}">'+
                  '<option value="">Select level4</option>'+
                  '</select>'+
                '</td>'+
                '<td>'+
                  '<select name="rec[{id}][level5]" required="required" class="form-control select2_single level5 level5{id}" data-id="{id}">'+
                  '<option value="">Select level5</option>'+
                  '<?php foreach ($level5 as $value) { ?>'+
                   '<option value="<?php echo $value['id'];?>" data-pid="<?php echo $value['assignid']; ?>"><?php echo $value['name'];?></option>'+
                    '<?php  } ?>'+
                  '</select>'+
                '</td>'+
                '<td>'+
                  '<input name="rec[{id}][amount]" data-id="{id}" type="number"  id="amount" class="form-control amount amount{id}" maxlength="20" required>'+
                '</td>'+
                '<td >RS:<span class="opbalance{id}"></span>/</td>'+
                '<td>'+
                  '<button class="btn btn-primary removeRow" data-id="{id}">'+
                    '<i class="fa fa-remove" type="button"></i>'+
                  '</button>'+
                '</td>'+
              '</tr>';
      String.prototype.replaceAll = function (find, replace) {
          var str = this;
          return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
      };
        $(document).on("click",".addRow",function(e){
                
          wrapper.append(row.replaceAll("{id}",++rows));
          $(".select2_single").select2({
            placeholder: "Select Level5",
            allowClear: true
         });
         e.preventDefault();
        });
        $(document).on("click",".removeRow",function(e){
          var length = $("tbody").children().length;
          var id = $(this).attr("data-id");
          if(length!=1)
            $(".row"+id).remove();
          e.preventDefault();
        });
        });
        $(".select2_single").select2({
            placeholder: "Select Level5",
            allowClear: true
         });
        </script>