<script type="text/javascript">
$(document).ready(function() {
    $('#editabledatatable').dataTable( {
         "destroy": true,
        "ajax": "<?php echo base_url(); ?>settings/taxes/gettaxcats",
        "lengthMenu": [[20, 50, 100], [20, 50, 100]],
        "language": {
            "lengthMenu": "<?php echo $this->lang->line("DISPLAY"); ?> _MENU_ <?php echo $this->lang->line("RECORDSPERPAGE"); ?>",
            "zeroRecords": "<?php echo $this->lang->line("NOTHINGFOUND"); ?>",
            "info": "<?php echo $this->lang->line("SHOWINGPAGE"); ?> _PAGE_ <?php echo $this->lang->line("OF"); ?> _PAGES_",
            "infoEmpty": "<?php echo $this->lang->line("NORECORDSAVAILABLE"); ?>",
            "infoFiltered": "(<?php echo $this->lang->line("FILTEREDFROM"); ?> _MAX_ <?php echo $this->lang->line("TOTALRECORDS"); ?>)",
            "search": "<?php echo $this->lang->line("SEARCH"); ?> : ",
            "paginate": {
                "previous": "<?php echo $this->lang->line("PREVIOUS"); ?>",
                "next":"<?php echo $this->lang->line("NEXT"); ?>"
            }
        },
        "columns": [
             { "data": "id",
              render: function (data, type, row, meta) {
               return meta.row + meta.settings._iDisplayStart + 1;
              } 
            },
            { "data": "NAME" },
            {
              "data": null,
                "mRender": function(data, type, full) {
                	return '<a class="btn btn-info shiny btn-xs" onclick="return myFunction(this.id)" data-toggle="modal" data-target="#myModal" id=' + data.ID + ' ' + 'href=#' + '><i class="fa fa-edit"></i></a>&nbsp;&nbsp;<a class="btn btn-danger btn-xs shiny delete" data-toggle="modal" data-target="#confirmmodal" onclick="return confirmFunction(this.id)" id=' + data.ID + ' ' + 'href=#' + '><i class="fa fa-trash-o"></i></a>';
               }
            }
        ]

    } );
} );

</script>

<script type="text/javascript">
  function myFunction(id) {
   // id = $(this).attr('id');
    $.ajax({
        url: base_url + 'settings/taxes/edittaxcats/'+ id,
        success:function(data){
            var json = $.parseJSON(data);
            $("#modaltitleheading").html("<?php echo $this->lang->line("EDIT"); ?>");
        for (var i=0;i<json.length;++i)
        {
            $("#id").val(json[i].ID);
            $("#name").val(json[i].NAME);
            $("#address").val(json[i].ADDRESS);
        }

        }
    });
}

function addnew1(){
    $("#modaltitleheading").html("<?php echo $this->lang->line("ADDNEW"); ?>");
    $("#id").val('');
    $("#name").val('');
    $("#addnewbutton").click();
}

function confirmFunction(id) {
    $("#okid").val(id);
}

  function deleteFunction() {
     id = $("#okid").val();
    $.ajax({
        url: base_url + 'settings/taxes/deletetaxcats/'+ id,
        success:function(data){
         location.reload(true);
          $("#confirmmodal").hide();
         $("#modal-success").show();

        }
    });
}
</script>
            <!-- Page Content -->
            <div class="page-content">
        
                <!-- Page Header -->
                <div class="page-header position-relative">
                     <div class="header-title">
                        <h1>
                          <?php echo $this->lang->line("TAXCATEGORY"); ?>
                        </h1>
                    </div>
                    <!--Header Buttons-->
                    <div class="header-buttons">
                        <a class="sidebar-toggler" href="#">
                            <i class="fa fa-arrows-h"></i>
                        </a>
                        <a class="refresh" id="refresh-toggler" href="">
                            <i class="glyphicon glyphicon-refresh"></i>
                        </a>
                        <a class="fullscreen" id="fullscreen-toggler" href="#">
                            <i class="glyphicon glyphicon-fullscreen"></i>
                        </a>
                    </div>
                    <!--Header Buttons End-->
                </div>
                <!-- /Page Header -->
                <!-- Page Body -->
                <div class="page-body">
                    <div class="row">
                        <div class="col-xs-12 col-md-12">
                            <div class="widget">
                              
                                 <?php
                            if ($this->session->flashdata('success_msg')) {

                                ?>


    <div class="alert alert-success">

        <a href="#" class="close" data-dismiss="alert">&times;</a>

       <?php echo $this->session->flashdata('success_msg'); $this->session->unset_userdata('success_msg');?>
    </div>

                        <?php
                            }
                            ?>
                                  
                    
                              
                                <div class="widget-body">
                                    <div class="table-toolbar">
                                       <div class="form-group"> <a class="btn btn-success shiny" type="button" onclick="addnew1()" href="javascript:void(0);" >
    <i class="fa fa-plus"></i>
</a></div>
<a data-toggle="modal" data-target="#myModal" id="addnewbutton" style="display: none;">testttt</a>
                                       
                                        <div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
    <form action="<?php echo base_url();?>settings/taxes/addtaxcats" method="post">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title" id="modaltitleheading"><?php echo $this->lang->line("ADDNEW"); ?></h4>
      </div>
      <div class="modal-body">
       <div class="row">
            <div class="col-md-12">
                <input type="hidden" id="id" name="id">
                <div class="form-group">
                    <input type="text" class="form-control" name="name" id="name" placeholder="<?php echo $this->lang->line("NAME"); ?>" required="">
                </div>
            </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-success"><?php echo $this->lang->line("SUBMIT"); ?></button>
        <button type="button" class="btn btn-danger" data-dismiss="modal"><?php echo $this->lang->line("CLOSE"); ?></button>
      </div>
  </form>
    </div>
</div>
 </div>


 <div id="modal-success" class="modal modal-message modal-success" style="display: none;">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <i class="glyphicon glyphicon-check"></i>
                </div>
                <div class="modal-title"><?php echo $this->lang->line("DELETESUCCESS"); ?></div>

                
                <div class="modal-footer">
                    <button type="button" class="btn btn-success" data-dismiss="modal"><?php echo $this->lang->line("OK"); ?></button>
                </div>
            </div> <!-- / .modal-content -->
        </div> <!-- / .modal-dialog -->
    </div>


     <div id="confirmmodal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title"><?php echo $this->lang->line("AREYOUSURETODELETE"); ?></h4>
      </div>
      <div class="modal-footer">
        <input type="hidden" id="okid" value="">
        <button type="button" class="btn btn-success" onclick="return deleteFunction()"><?php echo $this->lang->line("OK"); ?></button>
        <button type="button" class="btn btn-danger" data-dismiss="modal"><?php echo $this->lang->line("CLOSE"); ?></button>
      </div>
    </div>
</div>

</div>
                                 <div class="table-responsive"> 
                                    <table class="table table-striped table-hover table-bordered editable" id="editabledatatable">
                                        <thead>
                                            <tr role="row">
                                                <th>
                                                    <?php echo $this->lang->line("ID"); ?>
                                                </th>
                                                <th>
                                                    <?php echo $this->lang->line("NAME"); ?>
                                                </th>
                    
                                                   <th>
                                                 <?php echo $this->lang->line("ACTION"); ?>
                                                </th>
                                            </tr>
                                        </thead>
                                    </table>
                                 </div>
                                </div>
                            </div>
                        </div>
                    </div>
                   
                </div>
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->
        </div>
        <!-- /Page Container -->
        <!-- Main Container -->

    </div>

