<script type="text/javascript">
    $(document).ready(function() {
        selectlocation();
        $(document).on('change', '.edittextlistmin', function() {
            var stid        = $(this).attr("data-id");
            var prstockmin  = $(this).val();
            var locationid  = $("#sellocation").val();
            var prid        = $(this).attr("data-prid");
            $.ajax({
                method: "POST",
                url: "<?php echo base_url('inventory/Reorderlevel/updateminstock'); ?>",
                data: {
                    stid: stid,
                    prstockmin: prstockmin,
                    locationid:locationid,
                    prid:prid
                },
            }).done(function (msg) {
                location.reload();
            });
        });
        $(document).on('change', '.edittextlistmax', function() {
            var stid        = $(this).attr("data-id");
            var prstockmax  = $(this).val();
            var locationid  = $("#sellocation").val();
            var prid        = $(this).attr("data-prid");
            $.ajax({
                method: "POST",
                url: "<?php echo base_url('inventory/Reorderlevel/updatemaxstock'); ?>",
                data: {
                    stid: stid,
                    prstockmax: prstockmax,
                    locationid:locationid,
                    prid:prid
                },
            }).done(function (msg) {
                location.reload();
            });
        });
    });

    function selectlocation() {
        var locationsel =   $("#sellocation").val();
        var searchbycategory =   $("#searchbycategory").val();
        $('#editabledatatable').dataTable( {
             "destroy": true,
            "ajax": "<?php echo base_url() ?>inventory/reorderlevel/getrecordlevel?locationsel="+locationsel+"&searchbycategory="+searchbycategory,
            "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": "CODE" },
                { "data": "PRODUCT" },
                { "data": "STOCK" },
                {"targets": [ 3 ],"sortable" : true  ,"render": function ( data, type, row ) {
                    if(row.MINIMUM!==null) {
                        return "<input type='number' class='edittextlistmin' value='"+row.MINIMUM+"' data-id='"+row.STOCKLEVELID+"' data-prid='"+row.PRODUCTID+"' />";
                    } else {
                        return "<input type='number' class='edittextlistmin' value='' data-id='"+row.STOCKLEVELID+"' data-prid='"+row.PRODUCTID+"' />";
                    }
                }},
                {"targets": [ 4 ],"sortable" : true  ,"render": function ( data, type, row ) {
                    if(row.MAXIMUM!==null) {
                        return "<input type='number' class='edittextlistmax' value='"+row.MAXIMUM+"' data-id='"+row.STOCKLEVELID+"' data-prid='"+row.PRODUCTID+"' />";
                    } else {
                        return "<input type='number' class='edittextlistmax' value='' data-id='"+row.STOCKLEVELID+"' data-prid='"+row.PRODUCTID+"' />";
                    }
                }},
            ]
        });
    }
</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("REORDERLEVELBYSTORE"); ?>
                        </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 style="margin-bottom: 15px;width: 100%;">
                                            <select class="form-control" name="sellocation" id="sellocation" onchange="selectlocation()" style="width: 300px;float: left;margin-right:10px;">
                                                <?php
                                                if($locations) {
                                                    foreach($locations as $locationsrec) {
                                                ?>
                                                    <option value="<?php echo $locationsrec->ID; ?>"><?php echo $locationsrec->NAME; ?></option>
                                                <?php
                                                    }
                                                }
                                                ?>
                                            </select>
                                            <select class="dt-column_div" id="searchbycategory" name="searchbycategory" style="width: 300px;" onchange="selectlocation()">
                                                <option value="">Search by Category</option>
                                                <?php
                                                if($categories) {
                                                    foreach($categories as $catrec) {
                                                ?>
                                                    <option value="<?php echo $catrec->ID; ?>"><?php echo $catrec->NAME; ?></option>
                                                <?php
                                                    }
                                                }
                                                ?>
                                            </select>
                                        </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("CODE"); ?></th>
                                                       <th>
                                                           <?php echo $this->lang->line("PRODUCT"); ?>
                                                       </th>
                                                       <th>
                                                           <?php echo $this->lang->line("STOCK"); ?>
                                                       </th>
                                                       <th>
                                                           <?php echo $this->lang->line("MINIMUM"); ?>
                                                       </th>
                                                       <th>
                                                           <?php echo $this->lang->line("MAXIMUM"); ?>
                                                       </th>
                                                   </tr>
                                               </thead>
                                           </table>
                                        </div>
                                    </div>
                            </div>
                        </div>
                    </div>
                   
                </div>
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->
        </div>
        <!-- /Page Container -->
        <!-- Main Container -->
    </div>
    <style type="text/css">
        .edittextlistmax, .edittextlistmin {
/*            width: 100%;
            height: 25px;
            padding: 4px;*/
            -webkit-border-radius: 0 !important;
            -webkit-background-clip: padding-box !important;
            -moz-border-radius: 0 !important;
            -moz-background-clip: padding !important;
            border-radius: 0 !important;
            background-clip: padding-box !important;
            color: #858585;
            background-color: #fbfbfb;
            border: 1px solid #d5d5d5;
            font-family: inherit;
            -webkit-transition: -webkit-box-shadow .45s,border-color .45s ease-in-out;
            -moz-transition: -moz-box-shadow .45s,border-color .45s ease-in-out;
            -o-transition: box-shadow .45s,border-color .45s ease-in-out;
            transition: box-shadow .45s,border-color .45s ease-in-out;
            -webkit-box-shadow: none;
            -moz-box-shadow: none;
            box-shadow: none;
                padding: 6px 12px;
                font-size: 13px;
                line-height: 1.42857143;    
        }
    </style>