<style type="text/css">
@media print
{
.noprint {display:none;}
}
</style>
<div class="wrapper">
    <div class="container">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">
                <div class="btn-group pull-right m-t-15">
                    <button type="button"  onclick="openaddnew();" class="btn btn-custom waves-effect waves-light" >Add <span class="m-l-5"><i class="fa fa-plus"></i></span></button>
                </div>
                <h4 class="page-title" >Business Stores</h4>
            </div>
            
            
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="card-box table-responsive">
                    
                    <h4 class="header-title m-t-0 m-b-30">&nbsp;</h4>

                    <table id="datatable-buttons" class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Store</th>
                                <th>Manager</th>
                                <th>Cell</th>
                                <th>Phone</th>
                                <th>Address</th>
                                <th>City</th>
                                <th class='noprint'>Action</th>
                            </tr>
                        </thead>

                        <tbody>
                            <?php if(isset($stores)) { foreach ($stores as $list){ ?>
                            <tr>
                                <td><?php echo $list['id_business_stores']; ?></td>
                                <td><?php echo $list['business_store']; ?></td>
                                <td><?php echo $list['store_manager']; ?></td>
                                <td><?php echo $list['store_cell']; ?></td>
                                <td><?php echo $list['store_phone1']; ?></td>
                                <td><?php echo $list['store_address']; ?></td>
                                <td><?php echo $list['store_city']; ?></td>
                                <td class='noprint' > 
                                    <button id='btnedit' onclick="openupdate(<?php echo $list['id_business_stores']; ?>);" class="btn btn-icon waves-effect waves-light btn-info m-b-5"> <i class="fa fa-keyboard-o"></i> </button> 
                                </td>
                            </tr>
                            <?php }} ?>
                        </tbody>
                    </table>
                </div>
            </div><!-- end col -->
        </div>
        <!-- end row -->
        
        <!--Modals-->
        
        <!--Add Service Category Modal-->
        <div id="addlist" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="addlist" aria-hidden="true" style="display: none;">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title" id="custom-width-modalLabel">Add a New Store</h4>
                    </div>
                    <div class="modal-body">
                        
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txtstorename" class="control-label">Store Name</label>
                                    <input type="text" class="form-control" placeholder="Store Name" id="txtstorename" name="txtstorename">
                                </div> 
                            </div> 
                        </div>
                        
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txtstoremanager" class="control-label">Manager</label>
                                    <input class="form-control" type="text" name="txtstoremanager" id="txtstoremanager"  />
                                </div> 
                            </div> 
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txtstorecell" class="control-label">Cell</label>
                                    <input class="form-control" type="text" name="txtstorecell" id="txtstorecell"  />
                                </div> 
                            </div> 
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txtstorephone1" class="control-label">Phone</label>
                                    <input class="form-control" type="text" name="txtstorephone1" id="txtstorephone1"  />
                                </div> 
                            </div> 
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txtstoreaddress" class="control-label">Address</label>
                                    <input class="form-control" type="text" name="txtstoreaddress" id="txtstoreaddress"  />
                                </div> 
                            </div> 
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txtstorecity" class="control-label">City</label>
                                    <input class="form-control" type="text" name="txtstorecity" id="txtstorecity"  />
                                </div> 
                            </div> 
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Close</button>
                        <button onclick="addnew();" type="button" class="btn btn-custom waves-effect waves-light">Save</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
        <!--End Service Category Modal-->
        
        <!--Edit Service Category Modal-->
        <div id="editstore" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="editstore" aria-hidden="true" style="display: none;">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title" id="custom-width-modalLabel">Edit Store</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txteditstoreid" class="control-label">ID</label>
                                    <input readonly="readonly" type="text" class="form-control" placeholder="ID" id="txteditstoreid" name="txteditstoreid">
                                </div> 
                            </div> 
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txteditstorename" class="control-label">Store Name</label>
                                    <input type="text" class="form-control" placeholder="Store Name" id="txteditstorename" name="txteditstorename">
                                </div> 
                            </div> 
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txteditstoremanager" class="control-label">Store Manager</label>
                                    <input type="text" class="form-control" placeholder="Store Manager" id="txteditstoremanager" name="txteditstoremanager">
                                </div> 
                            </div> 
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txteditstorephone1" class="control-label">Store Phone</label>
                                    <input type="text" class="form-control" placeholder="Store Phone" id="txteditstorephone1" name="txteditstorephone1">
                                </div> 
                            </div> 
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txteditstorecell" class="control-label">Store Cell</label>
                                    <input type="text" class="form-control" placeholder="Store Cell" id="txteditstorecell" name="txteditstorecell">
                                </div> 
                            </div> 
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txteditstoreaddress" class="control-label">Store Address</label>
                                    <input type="text" class="form-control" placeholder="Store Address" id="txteditstoreaddress" name="txteditstoreaddress">
                                </div> 
                            </div> 
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txteditstorecity" class="control-label">Store City</label>
                                    <input type="text" class="form-control" placeholder="Store City" id="txteditstorecity" name="txteditstorecity">
                                </div> 
                            </div> 
                        </div>
                         
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Close</button>
                        <button onclick="update();" type="button" class="btn btn-custom waves-effect waves-light">Save</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
        <!--End Edit Service Category Modal-->
        
        
        <script>
           $(document).ready(function() {

                $('#datatable-buttons').DataTable({
                    lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]],
                    stateSave: true,
                    dom: "Bfrtlip",
                    buttons: [{extend: "copy", className: "btn-sm btn-custom btn-trans"}, {extend: "csv", className: "btn-sm btn-pink btn-trans"}, {
                            extend: "excel",
                            className: "btn-sm btn-warning btn-trans"
                        }, {extend: "pdf", className: "btn-sm btn-purple btn-trans"}],
                    responsive: !0,
                    "aoColumns": [
                        null,
                        null,
                        null,
                        { "orderSequence": [ "asc" ] },
                        null
                    ]
                });
                
                
                 toastr.options = {
                    "closeButton": true,
                    "debug": true,
                    "newestOnTop": true,
                    "progressBar": true,
                    "positionClass": "toast-bottom-center",
                    "preventDuplicates": true,
                    "onclick": null,
                    "showDuration": "300",
                    "hideDuration": "1000",
                    "timeOut": "5000",
                    "extendedTimeOut": "1000",
                    "showEasing": "swing",
                    "hideEasing": "linear",
                    "showMethod": "fadeIn",
                    "hideMethod": "fadeOut"
                }
                
                $(".vertical-spin").TouchSpin({
                    verticalbuttons: true,
                    buttondown_class: "btn btn-primary",
                    buttonup_class: "btn btn-primary",
                    verticalupclass: 'ti-plus',
                    verticaldownclass: 'ti-minus'
                });
                var vspinTrue = $(".vertical-spin").TouchSpin({
                    verticalbuttons: true
                });
                if (vspinTrue) {
                    $('.vertical-spin').prev('.bootstrap-touchspin-prefix').remove();
                }
                
            });
            
            function orderservicetype(id, orderid){
                var type = "colortype";
                
                if(id && orderid){
                    $.ajax({
                        type: 'POST',
                        url: '<?php echo base_url(); ?>/service_controller/order_function',
                        data:{id: id, orderid: orderid, type: type},
                        success: function(data){
                            //toastr.success(data, 'Order changed');
                            location.reload();
                        }
                    });
                }
            }

            function deletecategory(catid){
                
                //Warning Message
                swal({
                    title: "Are you sure?",
                    text: "This action will also remove all services in this category!",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonClass: 'btn-warning',
                    confirmButtonText: "Yes, remove it!",
                    closeOnConfirm: true
                }, function (){
                    $.ajax({
                        type: 'POST',
                        url: 'service_controller/delete_category',
                        data: {id_service_category: catid},
                        success: function(data) {
                            var result = data.split("|");
                            
                            if (result[0] === "success") {
                                swal("Deleted!", "Service Category and all its Services have been removed.", "success");
                                location.reload();
                            } else {
                                swal("Error!", "Service Category was not removed!.", "error");
                            }
                        } 
                    });
                });
            }
            
            function openaddnew(){
                $("#addlist").modal('show');
            }
            
            function addnew(){
                if($("#txtstorename").val()!== ""){
                $.ajax({
                        type: 'POST',
                        url: 'store_controller/add_store',
                        data: {
                            business_store: $("#txtstorename").val(), 
                            store_manager: $("#txtstoremanager").val(),
                            store_cell: $("#txtstorecell").val(),
                            store_phone1: $("#txtstorephone1").val(),
                            store_address: $("#txtstoreaddress").val(),
                            store_city: $("#txtstorecity").val()
                        
                        },
                        
                        success: function(data) {
                            var result = data.split("|");
                            if (result[0] === "success") {
                                toastr.success(data, 'New Color Type Added');
                                location.reload();
                            }
                        }
                    });
                }
            }
            
            
            function openupdate(id){
                
                $.ajax({
                    type: 'POST',
                    url: '<?php echo base_url(); ?>store_controller/edit_store',
                    data: {id_business_stores: id},
                    dataType: "json",
                    cache: false,
                    async: true,
                    success: function(data){
                        $("#txteditstoreid").val(data.id_business_stores);
                        $("#txteditstorename").val(data.business_store);
                        $("#txteditstoremanager").val(data.store_manager);
                        $("#txteditstorecell").val(data.store_cell);
                        $("#txteditstorephone1").val(data.store_phone1);
                        $("#txteditstoreaddress").val(data.store_address);
                        $("#txteditstorecity").val(data.store_city);
                        $("#editstore").modal('show');
                        
                    }
                });
            }
            
        function update(){
                if($("#txteditstoreid").val()!== ""){
                $.ajax({
                        type: 'POST',
                        url: 'store_controller/update_store',
                        data: {
                            id_business_stores: $("#txteditstoreid").val(), 
                            business_store: $("#txteditstorename").val(), 
                            store_manager: $("#txteditstoremanager").val(),
                            store_cell: $("#txteditstorecell").val(),
                            store_phone1: $("#txteditstorephone1").val(),
                            store_address: $("#txteditstoreaddress").val(),
                            store_city: $("#txteditstorecity").val()
                        },
                        success: function(data) {
                            var result = data.split("|");
                            if (result[0] === "success") {
                                toastr.success(data, 'Store Updated');
                                location.reload();
                            }
                        }
                    });
                }
            }
       
        </script>