        <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">Franchises</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="tblsupplier" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
                                <thead>
                                    <tr>
                                        <th>Franchise ID</th>
                                        <th>Franchise NTN</th>
                                        <th>Franchise Name</th>
                                        <th>Franchise Contact</th>
                                        <th>Franchise Owner</th>
                                        <th>Office Phone</th>
                                        <th>Address</th>
                                        <th>Email</th>                                        
                                        <th>Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($franchises as $franchise){?>
                                    <tr>
                                        <td><?php echo $franchise['id_franchises']; ?></td>
                                        <td><?php echo $franchise['franchise_ntn']; ?></td>
                                        <td><?php echo $franchise['franchise_name']; ?></td>
                                        <td><?php echo $franchise['franchise_contact']; ?></td>
                                        <td><?php echo $franchise['franchise_owner']; ?></td>
                                        <td><?php echo $franchise['franchise_office_phone']; ?></td>
                                        <td><?php echo $franchise['franchise_address']; ?></td>
                                        <td><?php echo $franchise['franchise_email']; ?></td>
                                        <td class='noprint'> 
                                            <button id='btnedit' onclick="openupdate(<?php echo $franchise['id_franchises']; ?>);" 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 Supplier Modal-->
        <div id="addfranchise" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="addfranchise" 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 Franchise</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txtsuppliername" class="control-label">Franchise Name</label>
                                            <input type="text" class="form-control" placeholder="Franchise Name" id="txtfranchisename" name="txtfranchisename">
                                        </div> 
                                    </div> 
                                </div>
                                
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txtfranchisentn" class="control-label">Franchise NTN</label>
                                            <input type="text" class="form-control" placeholder="NTN" id="txtfranchisentn" name="txtfranchisentn">
                                        </div> 
                                    </div> 
                                </div>
                                 <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txtfranchiseowner" class="control-label">Owner</label>
                                            <input type="text" class="form-control" placeholder="Owner" id="txtfranchiseowner" name="txtfranchiseowner">
                                        </div> 
                                    </div> 
                                </div>
                               
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txtfranchisediscount" class="control-label">Agreed Discount</label>
                                            <input type="text" class="form-control decimal" placeholder="Agreed Discount" id="txtfranchisediscount" name="txtfranchisediscount">
                                        </div> 
                                    </div> 
                                </div>
                               
                                
                            </div>
                            <div class="col-lg-6">
                                 <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txtfranchiseofficephone" class="control-label">Office Phone</label>
                                            <input type="text" class="form-control numeric" placeholder="Office Phone" id="txtfranchiseofficephone" name="txtfranchiseofficephone">
                                        </div> 
                                    </div> 
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txtfranchisecontact" class="control-label">Contact</label>
                                            <input type="text" class="form-control" placeholder="Contact" id="txtfranchisecontact" name="txtfranchisecontact">
                                        </div> 
                                    </div> 
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txtfranchiseemail" class="control-label">Email</label>
                                            <input type="text" class="form-control" placeholder="Email" id="txtfranchiseemail" name="txtfranchiseemail">
                                        </div> 
                                    </div> 
                                </div>
                                 <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txtfranchisecredit" class="control-label">Credit Limit</label>
                                            <input type="text" class="form-control decimal" placeholder="Credit Limit" id="txtfranchisecredit" name="txtfranchisecredit">
                                        </div> 
                                    </div> 
                                </div>
                            </div>
                            <div class="row">
                                <div class=" col-md-12">
                                     <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="txtfranchiseaddress" class="control-label">Address</label>
                                            <input type="text" class="form-control" placeholder="Address" id="txtfranchiseaddress" name="txtfranchiseaddress">
                                        </div> 
                                    </div> 
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="txtfranchisecity" class="control-label">City</label>
                                            <input type="text" class="form-control" placeholder="City" id="txtfranchisecity" name="txtfranchisecity">
                                        </div> 
                                    </div>      
                                </div>
                                </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 Supplier Modal-->
        <div id="editfranchise" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="editfranchise" 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 Franchise</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="txteditfranchiseid" class="control-label">Franchise ID</label>
                                    <input type="text" class="form-control" placeholder="Franchise ID" readonly="readonly" id="txteditfranchiseid" name="txteditfranchiseid">
                                </div> 
                            </div> 
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txteditfranchisename" class="control-label">Franchise Name</label>
                                            <input type="text" class="form-control" placeholder="Franchise Name" id="txteditfranchisename" name="txteditfranchisename">
                                        </div> 
                                    </div> 
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txteditfranchiseowner" class="control-label">Owner</label>
                                            <input type="text" class="form-control " placeholder="Owner" id="txteditfranchiseowner" name="txteditfranchiseowner">
                                        </div> 
                                    </div> 
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txteditfranchisecontact" class="control-label">Contact</label>
                                            <input type="text" class="form-control" placeholder="Contact" id="txteditfranchisecontact" name="txteditfranchisecontact">
                                        </div> 
                                    </div> 
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txteditfranchisediscount" class="control-label">Agreed Discount</label>
                                            <input type="text" class="form-control decimal" placeholder="Agreed Discount" id="txteditfranchisediscount" name="txteditfranchisediscount">
                                        </div> 
                                    </div> 
                                </div>
                            </div>

                            <div class="col-md-6">
                                
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txteditfranchisentn" class="control-label">NTN</label>
                                            <input type="text" class="form-control " placeholder="NTN" id="txteditfranchisentn" name="txteditfranchisentn">
                                        </div> 
                                    </div> 
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txteditfranchiseofficephone" class="control-label">Office Phone</label>
                                            <input type="text" class="form-control numeric" placeholder="Office Phone" id="txteditfranchiseofficephone" name="txteditfranchiseofficephone">
                                        </div> 
                                    </div> 
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txteditfranchiseemail" class="control-label">Email</label>
                                            <input type="text" class="form-control" placeholder="Email" id="txteditfranchiseemail" name="txteditfranchiseemail">
                                        </div> 
                                    </div> 
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="txteditfranchisecredit" class="control-label">Credit Limit</label>
                                            <input type="text" class="form-control decimal" placeholder="Credit Limit" id="txteditfranchisecredit" name="txteditfranchisecredit">
                                        </div> 
                                    </div> 
                                </div>                        
                            </div>
                            
                            <div class="row">
                               <div class="col-md-6">
                                   <div class="form-group">
                                       <label for="txteditfranchiseaddress" class="control-label">Address</label>
                                       <input type="text" class="form-control" placeholder="Address" id="txteditfranchiseaddress" name="txteditfranchiseaddress">
                                   </div> 
                               </div> 
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="txtexitfranchisecity" class="control-label">City</label>
                                        <input type="text" class="form-control" placeholder="City" id="txtexitfranchisecity" name="txtexitfranchisecity">
                                    </div> 
                                </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 type="text/javascript">
         $(document).ready(function() {

                $('#tblsupplier').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
                });
                
                
                 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"
                }

             $(".numeric").keypress(function(e) {
                    //if the letter is not digit then display error and don't type anything
                    if (e.which != 13 && e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
                        return false;
                    }
                });
                
            $(".decimal").keypress(function(e) {
                //if the letter is not digit then display error and don't type anything
                if (e.which != 13 && e.which != 8 && e.which != 0  && e.which != 46 && (e.which < 48 || e.which > 57) ) {

                    return false;
                }
            });
                //Two Select box for products insert moving....Start
                $('#brandad1').on('change', function() {
                    var val1 = $("#brandad1 option:selected").val();
                    var txt1 = $("#brandad1 option:selected").text();
                    
                    
                    $('#brandad2 option').each(function() {
                        if($(this).attr('value') == val1){
                            alert("already exist!");die;
                        }
                    });
                    
                    $('#brandad2').append('<option selected value="'+val1+'">'+txt1+'</opiton>');
     
                });
                $('#brandad2').on('click', function() {
                    $("#brandad2 option:selected").remove();
                    $('#brandad2').find('option').prop('selected',true);
                });
                //Two Select box for products insert moving....End
                
                //Two Select box for products insert moving....Start
                $('#brandad3').on('change', function() {
                    var val1 = $("#brandad3 option:selected").val();
                    var txt1 = $("#brandad3 option:selected").text();
                    
                    
                    $('#brandad4 option').each(function() {
                        if($(this).attr('value') == val1){
                            alert("already exist!");die;
                        }
                    });
                    
                    $('#brandad4').append('<option selected value="'+val1+'">'+txt1+'</opiton>');
     
                });
                $('#brandad4').on('click', function() {
                    $("#brandad4 option:selected").remove();
                    $('#brandad4').find('option').prop('selected',true);
                });
                //Two Select box for products insert moving....End
                
            });
  
        function openupdate(id_franchises){
                
            $.ajax({
                    type: 'POST',
                    url: '<?php echo base_url(); ?>franchise_controller/edit_franchise',
                    data: {id_franchises: id_franchises},
                    dataType: "json",
                    cache: false,
                    async: true,
                    success: function(data){
                        
                        $("#txteditfranchiseid").val(id_franchises);
                        $("#txteditfranchisename").val(data.franchise_name);
                        $("#txteditfranchisecontact").val(data.franchise_contact);
                        $("#txteditfranchisentn").val(data.franchise_ntn);
                        $("#txteditfranchiseofficephone").val(data.franchise_office_phone);
                        $("#txteditfranchiseowner").val(data.franchise_owner);
                        $("#txteditfranchiseaddress").val(data.franchise_address);
                        $("#txteditfranchiseemail").val(data.franchise_email);
                        $("#txteditfranchisediscount").val(data.franchise_discount);
                        $("#txteditfranchisecredit").val(data.franchise_limit);
                    }
                });
            
            $("#editfranchise").modal('show');
            
            
        }
        function update(){
            if($("#txteditfranchiseid").val()!== ""){
                   
                $.ajax({
                        type: 'POST',
                        url: 'franchise_controller/update_franchise',
                        data: {
                            id_franchises: $("#txteditfranchiseid").val(), 
                            franchise_name: $("#txteditfranchisename").val(), 
                            franchise_ntn: $("#txteditfranchisentn").val(), 
                            franchise_contact:$("#txteditfranchisecontact").val(), 
                            franchise_owner: $("#txteditfranchiseowner").val(), 
                            franchise_office_phone: $("#txteditfranchiseofficephone").val(), 
                            franchise_email: $("#txteditfranchiseemail").val(), 
                            franchise_address:$("#txteditfranchiseaddress").val(),
                            franchise_discount:$("#txteditfranchisediscount").val(),
                            franchise_limit:$("#txteditfranchisecredit").val()
                            },
                        success: function(data) {
                            var result = data.split("|");
                            if (result[0] === "success") {
                                toastr.success(data, 'Service Updated');
                                location.reload();
                            }
                        }
                    });
                }
            }
        
        function openaddnew(){
            $("#addfranchise").modal('show');
        }
        
        
        function addnew(){
            if($("#txtfranchisename").val()!== "" ){
            
            
            $.ajax({
                    type: 'POST',
                    url: '<?php echo base_url();?>franchise_controller/addnewfranchise',
                    data: {
                        franchise_name: $("#txtfranchisename").val(), 
                        franchise_address:$("#txtfranchiseaddress").val(), 
                        franchise_contact: $("#txtfranchisecontact").val(), 
                        franchise_ntn: $("#txtfranchisentn").val(), 
                        franchise_owner: $("#txtfranchiseowner").val(), 
                        franchise_office_phone: $("#txtfranchiseofficephone").val(), 
                        franchise_email: $("#txtfranchiseemail").val(),
                        franchise_discount:$("#txtfranchisediscount").val(),
                        franchise_limit:$("#txtfranchisecredit").val()
                        },
                    success: function(data) {
                        var result = data.split("|");
                        if (result[0] === "success") {
                            toastr.success(data, 'New Supplier Added');
                            location.reload();
                        }
                    }
                });
            }
        }
      
        
    </script>
