  <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>Budget</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>View <?php echo $this->account_model->id_('head',$type,'id')['name']; ?> Budget</h2>
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a></li>
                      <form  method="post" action="<?php echo  base_url(); ?>account/incomebudget/">
                       <input type="hidden" name="date1" value="<?php echo $date1; ?>" >
                    <input type="hidden" name="date2" value="<?php echo $date2; ?>" >
                    <input type="hidden" name="type" value="<?php echo $type; ?>" >
                    <button type="submit" class="btn"><i class="fa fa-edit"></i></button>
                    </form>
                      </form>
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content ">
                  <style>
                 .form-control{
                     font-size: 12px;
                     padding:0px;
                 }
                  </style>
                     <table id="myDataTable" class="table table-bordered table-responsive">
                    <thead>
                    <tr>
                    
                    <th>#</th>
                    <th>Head</th>
                    <?php foreach ($date as $key => $value) { ?>
                        <th class="th"><input type="hidden" name="month[]" value="<?php echo  $value['month']; ?>"><?php echo date('y-F',strtotime($value['month'])); ?> </th>
                   <?php  } ?>
                    <th>Total</th>
                    
                    </tr>
                    </thead>
                    <tbody>
                    <?php  foreach ($head as $key => $value) { ?>
                    <tr>
                    <td><?php echo $key++; ?></td>
                    <td><input  type="hidden" name="income[<?php echo $key; ?>][head]" value="<?php echo $value['id']; ?>" /> <?php echo $value['name']; ?></td>
                    <?php $i=0; foreach ($date as $n => $dat) { 
                   
                       $v=$this->account_model->findbudget($value['id'],$dat['month']);
                       ?>
                    <td> <?php echo $v; ?> <input type="hidden" value="<?php echo $v; ?>" name="income[<?php echo $key; ?>][price][]" class="form-control num price-hr price-hr<?php echo $key;?> price-vr price-vr<?php echo $i; ?>" data-vr="<?php echo $i; ?>" data-id="<?php echo $key ?>" /></td>
                    <?php $i++; } ?>
                    <td class="total total<?php echo $key ?>"></td>
                    </tr>

                    <?php  } ?>
                    <tr><td></td><td>Total</td><?php foreach ($date as $key => $value) { ?><td class="totaldown<?php echo $key; ?>"></td><?php } ?><td class="finaltotal"></td></tr>
                    </tbody>
                    </table>
                    
                     <div class="ln_solid"></div>
                      
                      
                          </div>
                    
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
         <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() {
        setTimeout(function(){
             
              
        $('#myDataTable').DataTable(
            {
            "bPaginate":false,
            "bFilter":true,
            "bInfo":false,
            "ordering":false,
            "scrollX":true,
            dom: 'Bfrtip',
            buttons: [
            'csv', 'excel', 'pdf',{extend:'print',text:'Print'}  ]
            }
        );
        
        // $('#myDataTable').DataTable();

       }, 2000);
        });
        
        </script>
         <script>
         $(document).ready(function(){

          setTimeout(function(){
             $('.price-hr').trigger('keyup');
             $('.price-vr').trigger('keyup');
              }, 1000);



         $('body').removeClass('nav-md');
         $('body').addClass('nav-sm');

            $(document).on('keyup','.price-hr',function(){
                
                var id=$(this).attr('data-id');
                var total=calculatepricevr(id);
                $('.total'+id).html(total);
                 var to=calculate_total();
                $('.finaltotal').html(to);
                
                    });
                function calculatepricevr(id){
                var Total = 0;
                //console.log('.price-vr'+id);
                $.each($('.price-hr'+id),function(i,v){
                var val = $(v).val();
                if(val=="")
                val = 0;
                Total += parseFloat( val );
                });
                return Total;

                }
          $(document).on('keyup','.price-vr',function(){               
                var id=$(this).attr('data-vr');
               var total=update_vertical(id);
                $('.totaldown'+id).html(total);
          });

          function update_vertical(id) {
              var Total = 0;
                
                $.each($('.price-vr'+id),function(i,v){
                var val = $(v).val();
                if(val=="")
                val = 0;
                Total += parseFloat( val );
                });
                return Total;
          }
          function calculate_total(){
            var total=0;
             $.each($('.total'),function(i,v){
                var val = parseInt($(v).html());
                if(val=="")
                val = 0;
                total += parseFloat( val );
                });
                return total;
          }

          

         });
         </script>