<script type="text/javascript">
    $(document).ready(function() {
        $('#editabledatatable').dataTable( {
             "destroy": true,
            "ajax": "<?php echo base_url(); ?>inventory/products/getauxiliaryproducts",
            "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": "PRODUCT" },
                { "data": "PRODUCT2" },
                {
                  "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 shiny btn-xs" data-toggle="modal" data-target="#confirmmodal" onclick="return confirmFunction(this.id)" id=' + data.ID + ' ' + 'href=#' + '>' + '<i class="fa fa-trash"></i>' + '</a>';
                   }
                }
            ]
        });
    });
</script>
<script type="text/javascript">
      function myFunction(id) {
       // id = $(this).attr('id');
        $.ajax({
            url: base_url + 'inventory/products/editauxiliaryproduct/'+ id,
            success:function(data){
                var json = $.parseJSON(data);
                for (var i=0;i<json.length;++i) {
                    $("#id").val(json[i].ID);
                    $("#product").val(json[i].PRODUCT);
                    $("#auxiliaryproduct").val(json[i].PRODUCT2);

                }
            }
        });
    }
    function confirmFunction(id) {
        $("#okid").val(id);
    }
    function deleteFunction() {
        id = $("#okid").val();
        $.ajax({
            url: base_url + 'inventory/products/deleteauxilaryproduct/'+ 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("AUXILIERYPRODUCTS"); ?>
                        </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 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 class="widget-body">
        <div class="table-toolbar">
            <div class="form-group">
                <a type="button" class="btn btn-success shiny"
                    data-toggle="modal" data-target="#myModal"
                    href="javascript:void(0);"><i class="fa fa-plus"></i>
                </a>
            </div>
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
        <form action="<?php echo base_url();?>inventory/products/addauxiliaryproduct" method="post" id="frmauxilieryproduct">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title"><?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">
                    <select name="product" id="product" class="form-control">
                        <option value=""><?php echo $this->lang->line("SELECTPRODUCT"); ?></option>
                         <?php foreach($product as $product_list) { ?>
                          <option value="<?php echo $product_list->ID;?>"><?php echo $product_list->NAME;?></option>
                        <?php } ?>

                    </select>
                </div>
                 <div class="form-group">
                    <select name="auxiliaryproduct" id="auxiliaryproduct" class="form-control">
                         <option value=""><?php echo $this->lang->line("SELECTAUXILIERYPRODUCT"); ?></option>
                         <?php foreach($auxilaryproduct as $auxilaryproduct_list) { ?>
                          <option value="<?php echo $auxilaryproduct_list->ID;?>"><?php echo $auxilaryproduct_list->NAME;?></option>
                        <?php } ?>
                    </select>
                </div>
            </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="submit" class="btn btn-success shiny"><?php echo $this->lang->line("SUBMIT"); ?></button>
        <button type="button" class="btn btn-danger shiny" data-dismiss="modal"><?php echo $this->lang->line("CLOSE"); ?></button>
      </div>
  </form>
    </div>
</div>
</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 shiny" onclick="return deleteFunction()"><?php echo $this->lang->line("OK"); ?></button>
        <button type="button" class="btn btn-danger shiny" data-dismiss="modal"><?php echo $this->lang->line("CLOSE"); ?></button>
      </div>
    </div>
</div>

</div>

                <div id="tablecontent" class="table-scrollable" style="border: none;">
                    <div id="myTable_processing" class="dataTables_processing" style="display: none;">Processing...</div>
                    <table class="table table-striped table-hover table-bordered editable" id="editabledatatable" style="width: 100%;">
                        <thead>
                            <tr role="row">
                                <th>
                                    <?php echo $this->lang->line("ID"); ?>
                                </th>
                                <th>
                                    <?php echo $this->lang->line("PRODUCT"); ?>
                                </th>

                                   <th><?php echo $this->lang->line("AUXILIERYPRODUCT"); ?></th>

                                   <th>
                                 
                                </th>
                            </tr>
                        </thead>
                    </table>
                </div>
               </div>
           </div>
       </div>
   </div>
                   
                </div>

                
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->
        </div>
        <!-- /Page Container -->
        <!-- Main Container -->
    </div>
    <script src="<?php echo base_url();?>assets/js/validation/bootstrapValidator.js"></script>
    <script type="text/javascript">
        $('#frmauxilieryproduct').bootstrapValidator({
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            submitHandler: function (validator, form, submitButton) {
                // Do nothing
            },
            fields: {
                product: {
                    validators: {
                        notEmpty: {
                            message: '<?php echo $this->lang->line("FIELDISREQUERD"); ?>'
                        }
                    }
                },
                auxiliaryproduct: {
                    validators: {
                        notEmpty: {
                            message: '<?php echo $this->lang->line("FIELDISREQUERD"); ?>'
                        }
                    }
                }
            }
        });
        $(document).ajaxStop(function () {
            $('.dataTables_processing').hide();
        });

        $(document).ajaxStart(function () {
            $('.dataTables_processing').show();
        }); 
        </script>