
        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
                <div class="title_left">
                    <h3>Journal Voucher</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" enctype="multipart/form-data" <?php if(!empty($values)){ echo "action=".base_url()."account/print_jv"; }else{ echo  "action=".base_url()."account/SaveTransactions"; }  ?>  method="post">
                     <input name="pic" type="file" id="slip" value="null" >
                     <input name="cheque" type="hidden" value="null" >
                     <div class="row">
                     <div class="col-md-11 ">
                      <div class="item form-group col-md-4">
                        <label class="control-label col-md-5 col-sm-4 col-xs-12" for="name">Voucher #<span class="required">*</span>
                        </label>
                        <div class="col-md-7 col-sm-7 col-xs-12">
                        <input name="voucher" <?php  if($values['voucher_no']!=null){echo "value=".$values['voucher_no']." disabled";} ?>    class="form-control " maxlength="20" required>                    
                        </div>
                      </div> 
                      <div class="item form-group col-md-4"  >
                        <label class="control-label col-md-4 col-sm-4 col-xs-12" for="name">Date<span class="required">*</span>
                        </label>
                        <div class="col-md-8 col-sm-8 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 col-md-4">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">To<span class="required">*</span>
                        </label>
                        <div class="col-md-8 col-sm-8 col-xs-12">
                        <input name="to"  id="to" <?php  if($values['name']!=null){echo "value=".$values['name']." disabled";} ?> class="form-control abc" maxlength="20" required>                    
                        </div>
                      </div> 
                      </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"  required><?php if($values['description']!=null){echo $values['description'] ;} ?></textarea>                    
                        </div>
                      </div>
                      <?php if($values==null){ ?> 
                       <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>Main Head</td><td>Level 2</td><td>Level 3</td><td>Level 4</td><td>Level 5</td><td>Dr</td><td>Cr</td>
                        </tr>
                        </thead>
                        <tbody>
                        <tr class="row_table row1">
                        <td>
                         <select  name="rec[1][main]"  class="form-control main main1" data-id="1"  required>
                              <option value="">Select Main Head</option>
                              <?php
                              foreach ($mainhead as $value) {
                                ?>
                                <option   value="<?php echo $value['id'];?>"><?php echo $value['name'];?></option>  
                                <?php
                              }  
                              ?>
                            </select>
                        </td>
                       <td>
                      <select <?php  if($values['level_2_id']!=0){echo "disabled";} ?> 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";} ?> 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";} ?> 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]"  class="form-control level5 level51" required>
                              <option value="">Select Head Level 5</option>
                              
                            </select>
                      </td>
                       <td>
                     <input name="rec[1][dr]" data-id="1"    class="form-control num dr dr1" maxlength="20" required>
                     <span class="errordr1"></span>
                     </td>
                     <td>
                     <input name="rec[1][cr]" data-id="1"    class="form-control num cr cr1" maxlength="20" required>
                     <span class="errorcr1"></span>
                      </td>
                      <td>
                      <button class="btn btn-primary" data-remove-id="1" type="button" >
                        <i class="fa fa-remove"></i>
                      </button>
                      </td>
                      </tr>
                      <tr class="row_table row2">
                        <td>
                         <select  name="rec[2][main]"  class="form-control main main2" data-id="2"  required>
                              <option value="">Select Main Head</option>
                              <?php
                              foreach ($mainhead as $value) {
                                ?>
                                <option   value="<?php echo $value['id'];?>"><?php echo $value['name'];?></option>  
                                <?php
                              }  
                              ?>
                            </select>
                        </td>
                       <td>
                      <select <?php  if($values['level_2_id']!=0){echo "disabled";} ?> name="rec[2][level2]" data-id="2"  class="form-control level2 level22" required>
                              <option value="">Select Head Level 2</option>
                              

                            </select>
                      </td>
                       <td>
                      <select <?php  if($values['level_3_id']!=0){echo "disabled";} ?> name="rec[2][level3]" data-id="2" id="level3" class="form-control level3 level32" required>
                              <option value="">Select Head Level 3</option>
                              
                            </select>
                      </td>
                       <td>
                      <select <?php  if($values['level4']!=0){echo "disabled";} ?> name="rec[2][level4]" data-id="2"  class="form-control level4 level42" required>
                              <option value="">Select Head Level 4</option>
                              
                            </select>
                      </td>
                       <td>
                      <select <?php  if($values['level5']!=0){echo "disabled";} ?> name="rec[2][level5]"  class="form-control level5 level52" required>
                              <option value="">Select Head Level 5</option>
                              
                            </select>
                      </td>
                       <td>
                     <input name="rec[2][dr]" data-id="2"    class="form-control num dr dr2" maxlength="20" required>
                     <span class="errordr2"></span>
                     </td>
                     <td>
                     <input name="rec[2][cr]" data-id="2"    class="form-control num cr cr2" maxlength="20" required>
                     <span class="errorcr2"></span>
                      </td>
                      <td>
                      <button class="btn btn-primary removeRow" data-remove-id="1" type="button" data-id="2">
                        <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">
                    <i class="fa fa-plus" ></i>
                          <button id="send" type="submit" class="btn btn-success pull-right">Add</button>
                           <input type="hidden" name="type" value="journal voucher" >
                        </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>
      $(document).ready(function(){
        $('#slip').hide();
      });

        $(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('change','.main',function(){
         
          var id=$(this).val();
         var val = $(this).attr("data-id");
          $.ajax({
                    url: "<?php echo base_url(); ?>Load_account/level2_assign/"+id,
                    data: {},
                      success: function( d ) {
                         var pre='<option value="">Select Head Level 2</option>';
                         
                          $( ".level2"+val ).html(pre+d);
  }
});

        });
        $(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','.level4',function(){
          var id=$(this).val();
           var val = $(this).attr("data-id");
          $.ajax({
                    url: "<?php echo base_url(); ?>Load_account/level5_assign/"+id,
                    data: {},
                      success: function( d ) {
                         var pre='<option value="">Select Head Level 5</option>';
                          $( ".level5"+val ).html(pre+d);
  }
});

        });
         

      
      $(document).ready(function(){
        var rows =2;
      var wrapper = $("tbody");
      var row = '<tr class="row_table row{id}">'+
                '<td>'+
                  '<select name="rec[{id}][main]" required="required" class="form-control main main{id}" data-id="{id}">'+
                    '<option value="">Select main</option>'+
                    '<?php foreach ($mainhead as $value) {?> <option   value="<?php echo $value['id'];?>"><?php echo $value['name'];?></option>'+
                    '<?php } ?>'+
                  '</select>'+
                '</td>'+
                '<td>'+
                  '<select name="rec[{id}][level2]" required="required" class="form-control level2 level2{id}" data-id="{id}">'+
                    '<option value="">Select level2</option>'+
                  '</select>'+
                '</td>'+
                '<td>'+
                  '<select name="rec[{id}][level3]" required="required" class="form-control level3 level3{id} " data-id="{id}">'+
                  '<option value="">Select level3</option>'+
                  '</select>'+
                '</td>'+
                '<td>'+
                  '<select name="rec[{id}][level4]" required="required" 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 level5 level5{id}" data-id="{id}">'+
                  '<option value="">Select level5</option>'+
                  '</select>'+
                '</td>'+
                '<td>'+
                  '<input name="rec[{id}][dr]" data-id="{id}"    class="form-control num dr dr{id}"  maxlength="20" required>'+
                  '<span class="errordr{id}"></span>'+
                '</td>'+
                '<td>'+
                  '<input name="rec[{id}][cr]" data-id="{id}"     class="form-control num cr cr{id}" maxlength="20" required>'+
                  '<span class="errorcr{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));
        wrapper.append(row.replaceAll("{id}",++rows));
         e.preventDefault();
        });
        $(document).on("click",".removeRow",function(e){
          var length = $("tbody").children().length;
          var id = $(this).attr("data-id");
          if(length!=2)
            if(id%2==0) {
            $(".row"+id).remove();
            var remove_id=id-1;
            $(".row"+remove_id).remove();
            }else {
            $(".row"+id).remove(); 
            var remove_id=parseInt(id)+1;
            $(".row"+remove_id).remove();              
            }
          e.preventDefault();
        });
        
       $(document).on('focus','.dr',function(){
        var vale = $(this).attr("data-id");
        $('.cr'+vale).attr("readonly",true);
        $('.dr'+vale).attr("readonly",false);
         if(vale%2==0) {
            var v=parseInt(vale)+1;
           var val1=$('.cr'+v).val();
           var val2=$('').val();
         }else{

         }

        });
        $(document).on('keyup','.dr',function(){
        var vale = $(this).attr("data-id");
        if(vale%2==0) {
            var v=parseInt(vale)-1;
           var val1=$('.cr'+v).val();
           var val2=$('.dr'+vale).val();
           if(val1==val2){
             $('.errorcr'+v).html("");
              $('.errordr'+vale).html("");
           }else{
             $('.errorcr'+v).addClass("text-danger");
              $('.errorcr'+v).html("Not Equal");
           }
         }else{
           var v=parseInt(vale)+1;
           var val1=$('.cr'+v).val();
           var val2=$('.dr'+vale).val();
           
           if(val1==val2){
             $('.errorcr'+v).html("");
              $('.errordr'+vale).html("");
           }else{
             console.log('.errorcr'+v);
             $('.errorcr'+v).addClass("text-danger");
              $('.errorcr'+v).html("Not Equal");
           }
         }

        });
        $(document).on('keyup','.cr',function(){
        var vale = $(this).attr("data-id");
        if(vale%2==0) {
            var v=parseInt(vale)-1;
           var val1=$('.dr'+v).val();
           var val2=$('.cr'+vale).val();
           if(val1==val2){
             $('.errordr'+v).html("");
              $('.errorcr'+vale).html("");
           }else{
             $('.errordr'+v).addClass("text-danger");
              $('.errordr'+v).html("Not Equal");
           }
         }else{
           var v=parseInt(vale)+1;
           var val1=$('.dr'+v).val();
           var val2=$('.cr'+vale).val();
           
           if(val1==val2){
             $('.errordr'+v).html("");
              $('.errorcr'+vale).html("");
           }else{
             console.log('.errorcr'+v);
             $('.errordr'+v).addClass("text-danger");
              $('.errordr'+v).html("Not Equal");
           }
         }

        });
        
         $(document).on('focus','.cr',function(){
         var va = $(this).attr("data-id");
          $('.dr'+va).attr("readonly",true);
          $('.cr'+va).attr("readonly",false);


        });
        });
        </script>