<style type="text/css">
    @media print
    {
        .noprint {display:none;}
    }
    .loader {
        position: fixed;
        left: 0px;
        top: 0px;
        width: 100%;
        height: 100%;
        z-index: 9999;
        background: url('<?php echo base_url(); ?>assets/images/page-loader-1.gif') 50% 50% no-repeat ;
        display: none;
    }
</style>
<div class="wrapper">
    <div class="container">
        <!-- Page-Title -->
        <div class="btn-group pull-right m-t-15">
            <button type="button"  onclick="openaddnew();" class="btn btn-primary waves-effect waves-light" >Add <span class="m-l-5"><i class="fa fa-plus"></i></span></button>
        </div>
        
        <div class="row">
            <div class="col-sm-12">
                <h4 class="page-title" >Product Kits:</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="tblkits" class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>SKU</th>
                                <th>Barcode</th>
                                <th>Product</th>
                                <th>Kit Qty</th>
                                <th>Qty per Unit</th>
                                <th>Cost</th>
                                <th>Price</th>
                                <th>Type</th>
                                <th>Edit</th>
                                <th>Add Products</th>
                            </tr>
                            
                        </thead>

                        <tbody>
                            <?php foreach($kits as $kit){?>
                            <tr>
                                <td><strong><?php echo $kit['id_business_products'];?></strong></td>
                                <td><strong><?php echo $kit['sku'];?></strong></td>
                                <td><strong><?php echo $kit['barcode_products'];?></strong></td>
                                <td><strong><?php echo $kit['product'];?></strong></strong></td>
                                <td></td>
                                <td></td>
                                <td><strong><?php echo $kit['purchase_price'];?></strong></td>
                                <td><strong><?php echo $kit['price'];?></strong></td>
                                <td><strong><?php echo $kit['product_type'];?></strong></td>
                                <td><button id='btnedit' onclick="openupdate(<?php echo $kit['id_business_products']; ?>);" class="btn btn-icon waves-effect waves-light btn-sm btn-info m-b-5"> <i class="fa fa-keyboard-o"></i> </button> </td>
                                <td><button id='btnproducts' onclick="openaddproducts(<?php echo $kit['id_business_products']; ?>);" class="btn btn-icon waves-effect waves-light btn-sm btn-warning m-b-5"> <i class="fa fa-cubes"></i> </button> </td>
                            </tr>
                                <?php foreach($kit['products'] as $products){?>
                                <tr>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td><?php echo $products['product'].' '.$products['qty_per_unit'].' '.$products['measure_unit'];?></td>
                                    <td><?php echo $products['kit_qty'].' '.$products['unit_type']; ?></td>
                                    <td><?php if($products['kit_measure_qty']>0){ echo $products['kit_measure_qty'];}else{echo $products['kit_qty'];}?></td>
                                    <td><?php if($products['kit_measure_qty']>0){echo $products['measure_unit'];}else{echo $products['unit_type'];}?></td>
                                    <td></td>
                                    <td></td>
                                    <td>
                                        <button id='btnproducts' onclick="remove(<?php echo $products['id_kit_config'];?>);" class="btn btn-icon waves-effect waves-light btn-sm btn-danger m-b-5"> <i class="fa fa-close"></i> </button>
                                    </td>
                                    <td>
                                        
                                        
                                    </td>
                                </tr>
                                <?php } ?>
                            <?php } ?>
                        </tbody>
                </div>
            </div>
         </div>
    </div>
    
    <!--Add Kits Modal-->
        <div id="addkit" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="addkit" aria-hidden="true" style="display: none;">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <form action="<?php echo base_url();?>productkits_controller/add_kits" method="post">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title" id="custom-width-modalLabel">Compile a new Product Kit</h4>
                    </div>
                    <div class="modal-body">
                        
                         <div class="row">
                             <div class="col-md-6">
                                <div class="form-group">
                                    <label for="txtbrandid" class="control-label">Brand</label>
                                    <select class="form-control brand" id="txtbrandid" name="brand_id">
                                        <?php foreach($brands as $brand){?>
                                        <option value="<?php echo $brand['id_business_brands'];?>">
                                            <?php echo $brand['business_brand_name'];?>
                                        </option>
                                        <?php } ?>
                                    </select>
                                </div> 
                            </div> 
                             
                            <div class="col-md-6">
                                <div class="form-group">  
                                    <label for="txtbusinessproduct" class="control-label">Kit Name</label>
                                    <input type="text" class="form-control" placeholder="Kit Name" id="txtbusinessproduct" name="product">
                                </div> 
                            </div> 
                        </div>
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="txtbusinesscategory" class="control-label">Category</label>
                                            <input type="text" class="form-control" placeholder="Category" id="txtbusinesscategory" name="category">
                                        </div> 
                                    </div> 
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="txtprofessional" class="control-label">Professional</label>
                                            <select class="form-control" name="professional" id="txtprofessional">
                                                <option value="n">No</option>
                                                 <option value="y">Yes</option>
                                            </select>
                                        </div> 
                                    </div> 
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="txtpurchaseprice" class="control-label">Purchase Price</label>
                                            <input readonly="readonly" type="text" class="form-control"  placeholder="Purchase Price" id="txtpurchaseprice" name="purchase_price">
                                        </div> 
                                    </div> 
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="txtprice" class="control-label">Selling Price</label>
                                            <input type="text" class="form-control" placeholder="Price" id="txtprice" name="price">
                                        </div> 
                                    </div> 
                                </div>
                                
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="txtunittype" class="control-label">Unit Type</label>
                                            <select class="form-control" name="unit_type" id="txtunittype">
                                                <?php foreach($unit_types as $ut){?>
                                                <option value="<?php echo $ut['unit_type']; ?>"><?php echo $ut['unit_type']; ?></option>
                                                <?php }?>
                                               
                                            </select>
                                        </div> 
                                    </div>
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="txtmeasurementunit" class="control-label">Measurement Unit</label>
                                            <select class="form-control" name="measure_unit" id="txtmeasurementunit">
                                                <?php foreach ($measurement_unit as $mu){ ?>
                                                <option value="<?php echo $mu['m_unit']; ?>"><?php echo $mu['m_unit']; ?></option>
                                                <?php } ?>
                                            </select>
                                        </div> 
                                    </div> 
                                
                                </div>

                            </div>
                            <div class="col-lg-6">
                                
                                 <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="txtsku" class="control-label">SKU</label>
                                            <input type="text" class="form-control" placeholder="Product SKU" id="txtsku" name="sku">
                                        </div> 
                                    </div> 
                                     <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="txtcommission" class="control-label">Commission</label>
                                            <input type="text" class="form-control decimal" placeholder="Commission" id="txtcommission" name="commission">
                                        </div> 
                                    </div> 
                                </div>
                                
                                
                                <div class="row">
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="txtbarcode" class="control-label">Barcode</label>
                                            <input type="text" class="form-control" placeholder="Barcode" id="txtbarcode" name="barcode_product">
                                        </div> 
                                    </div> 
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="txtproducttype" class="control-label"><span style="color:red;">*Type</span></label>
                                            <select  class="form-control" id="txtproducttype" name="product_type">
                                                <?php foreach($product_types as $product_type){?>
                                                <?php if($product_type['product_type_name']=='Compiled Kit'){?>
                                                <option value="<?php echo $product_type['product_type_name'];?>"><?php echo $product_type['product_type_name'];?></option>
                                                <?php } ?>
                                                <?php } ?>
                                            </select>
                                        </div> 
                                    </div> 
                                
                                </div>
                                
                                
                                

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="txtqtyperunit" class="control-label">Quantity per unit</label>
                                            <input type="text" class="form-control numeric" placeholder="Quantity per unit" id="txtqtyperunit" name="qty_per_unit">
                                        </div> 
                                    </div> 
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="txtthreshold" class="control-label">Threshold</label>
                                            <input type="text" class="form-control" placeholder="Procurement Threshold" id="txtthreshold" name="product_threshold">
                                        </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 type="submit" class="btn btn-custom waves-effect waves-light">Save</button>
                    </div>
                    </form>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
        <!--End Add Kits Modal-->
        
        <!--Edit Kits Modal-->
        <div id="editkit" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="editkit" aria-hidden="true" style="display: none;">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <form action="<?php echo base_url();?>productkits_controller/update_kits" method="post">
                    <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 a Product Kit</h4>
                    </div>
                    <div class="modal-body">
                        
                         <div class="row">
                             <div class="col-md-4">
                                <div class="form-group">  
                                    <label for="editproductid" class="control-label">Kit ID</label>
                                    <input readonly="readonly" type="text" class="form-control" placeholder="Kit ID" id="editkitid" name="editproductid">
                                </div> 
                            </div> 
                             <div class="col-md-4">
                                <div class="form-group">
                                    <label for="editbrandid" class="control-label">Brand</label>
                                    <select class="form-control brand" id="editbrandid" name="brand_id">
                                        <?php foreach($brands as $brand){?>
                                        <option value="<?php echo $brand['id_business_brands'];?>">
                                            <?php echo $brand['business_brand_name'];?>
                                        </option>
                                        <?php } ?>
                                    </select>
                                </div> 
                            </div> 
                             
                            <div class="col-md-4">
                                <div class="form-group">  
                                    <label for="editproduct" class="control-label">Kit Name</label>
                                    <input type="text" class="form-control" placeholder="Kit Name" id="editproduct" name="product">
                                </div> 
                            </div> 
                        </div>
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="editcategory" class="control-label">Category</label>
                                            <input type="text" class="form-control" placeholder="Category" id="editcategory" name="category">
                                        </div> 
                                    </div> 
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="editprofessional" class="control-label">Professional</label>
                                            <select class="form-control" name="professional" id="editprofessional">
                                                <option value="n">No</option>
                                                 <option value="y" >Yes</option>
                                            </select>
                                        </div> 
                                    </div> 
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="editpurchaseprice" class="control-label">Purchase Price</label>
                                            <input readonly="readonly" type="text" class="form-control"  placeholder="Purchase Price" id="editpurchaseprice" name="purchase_price">
                                        </div> 
                                    </div> 
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="editprice" class="control-label">Selling Price</label>
                                            <input type="text" class="form-control" placeholder="Price" id="editprice" name="price">
                                        </div> 
                                    </div> 
                                </div>
                                
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="editunittype" class="control-label">Unit Type</label>
                                            <select class="form-control" name="unit_type" id="editunittype">
                                                <?php foreach($unit_types as $ut){?>
                                                <option value="<?php echo $ut['unit_type']; ?>"><?php echo $ut['unit_type']; ?></option>
                                                <?php }?>
                                               
                                            </select>
                                        </div> 
                                    </div>
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="editmeasurementunit" class="control-label">Measurement Unit</label>
                                            <select class="form-control" name="measure_unit" id="editmeasurementunit">
                                                <?php foreach ($measurement_unit as $mu){ ?>
                                                <option value="<?php echo $mu['m_unit']; ?>"><?php echo $mu['m_unit']; ?></option>
                                                <?php } ?>
                                            </select>
                                        </div> 
                                    </div> 
                                
                                </div>

                            </div>
                            <div class="col-lg-6">
                                
                                 <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="editsku" class="control-label">SKU</label>
                                            <input type="text" class="form-control" placeholder="Product SKU" id="editsku" name="sku">
                                        </div> 
                                    </div> 
                                     <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="editcommission" class="control-label">Commission</label>
                                            <input type="text" class="form-control decimal" placeholder="Commission" id="editcommission" name="commission">
                                        </div> 
                                    </div> 
                                </div>
                                
                                
                                <div class="row">
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="editbarcode" class="control-label">Barcode</label>
                                            <input type="text" class="form-control" placeholder="Barcode" id="editbarcode" name="barcode_product">
                                        </div> 
                                    </div> 
                                    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="editproducttype" class="control-label"><span style="color:red;">*Type</span></label>
                                            <select  class="form-control" id="editproducttype" name="product_type">
                                                <?php foreach($product_types as $product_type){?>
                                                <?php if($product_type['product_type_name']=='Compiled Kit'){?>
                                                <option value="<?php echo $product_type['product_type_name'];?>"><?php echo $product_type['product_type_name'];?></option>
                                                <?php } ?>
                                                <?php } ?>
                                            </select>
                                        </div> 
                                    </div> 
                                
                                </div>
                                
                                
                                

                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="editqtyperunit" class="control-label">Quantity per unit</label>
                                            <input type="text" class="form-control numeric" placeholder="Quantity per unit" id="editqtyperunit" name="qty_per_unit">
                                        </div> 
                                    </div> 
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="editthreshold" class="control-label">Threshold</label>
                                            <input type="text" class="form-control" placeholder="Procurement Threshold" id="editthreshold" name="product_threshold">
                                        </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 type="submit" class="btn btn-custom waves-effect waves-light">Save</button>
                    </div>
                    </form>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
        <!--End Edit Kits Modal-->    
        
        <!--Add Products To Kit Modal-->
        <div id="addkitproducts" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="addkitproducts" aria-hidden="true" style="display: none;">
            <div class="modal-dialog modal-md">
                <div class="modal-content">
                    <form action="<?php echo base_url();?>productkits_controller/add_kit_products" method="post">
                        <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 Products to Kit: <span id="addkitproducts_kitid"></span></h4>
                        </div>
                        <div class="modal-body">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="brands" class="control-label">Select Brand</label>
                                        
                                        <select class="form-control brand" id="brand" name="brand_id">
                                            <option value="">Select</option>
                                            <?php foreach($brands as $brand){?>
                                            <option value="<?php echo $brand['id_business_brands'];?>">
                                                <?php echo $brand['business_brand_name'];?>
                                            </option>
                                            <?php } ?>
                                        </select>                                        
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="kit-products" class="control-label">Select Product</label>
                                        <select onchange="$('#kit_measure_unit').val($('#kit-products option:selected').attr('measure_unit')); $('#kit_unit_type').val($('#kit-products option:selected').attr('unit_type')); $('#qty_per_unit').val($('#kit-products option:selected').attr('qty_per_unit'));" type="text" class='form-control' id="kit-products" name="kit-products">
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="kit_qty" class="control-label">Measure Qty</label>
                                        <input onkeyup="if(parseFloat($(this).val())>0){$('#unit_qty').val('0');}" type="text" class='form-control decimal' id="kit_qty" name="measure_qty"  placeholder="Measure Qty">
                                    </div>
                                </div>
                                      
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="measure_unit" class="control-label">Measure Unit</label>
                                        <input readonly="readonly" type="text" class='form-control ' id="kit_measure_unit" name="meaure_unit"  placeholder="Meaure Unit">
                                    </div>
                                </div>
                                                           
                                 <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="unit_qty" class="control-label">Unit Qty</label>
                                        <input onkeyup="if(parseFloat($(this).val())>0){$('#kit_qty').val('0');}" type="text" class='form-control numeric' id="unit_qty" name="unit_qty" placeholder="Unit Qty">
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="measure_unit" class="control-label">Unit Type</label>
                                        <input readonly="readonly" type="text" class='form-control' id="kit_unit_type" name="unit_type"  placeholder="Unit Type">
                                        <input type="hidden" class='form-control' id="qty_per_unit" name="qty_per_unit">
                                        <input type="hidden" class='form-control' id="kit_id" name="kit_id">
                                    </div>
                                </div>
                            </div>
                            <div id="loader" class="loader"></div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Close</button>
                            <button type="submit" class="btn btn-custom waves-effect waves-light">Save</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
                        
        
        <!--End Products To Kit Modal-->
    <script>
        
        $(document).ready(function() {
            
            $(".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;
                }
            });
            $(".brand").select2();
            
            
            $('#tblkits').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"}],
                    "ordering": false,
                    responsive: !0
                });
                
                $(document.body).on("change", "#brand", function() {
                    var brandid = $(this).val();
                    if (brandid && brandid != "") {
                        $(".loader").fadeIn("slow");
                        $("#kit-products").select2('val', 'All');
                        $.ajax({
                            type: 'POST',
                            //url: '<?php //echo base_url("purchaseorder_controller/brand_product");    ?>/' + brandid,
                            url: '<?php echo base_url("purchaseorder_controller/brand_product"); ?>',
                            data: {brandid: brandid, businessid: $("#businessid option:selected").val()},
                            dataType: "json",
                            cache: false,
                            async: true,
                            success: function(data) {
                                $('#kit-products').html('');
                                //$('#productedit').html('');
                                $('#kit-products').append('<option value = ""></option>');
                                if (data.length > 0) {
                                    for (var i = 0; i < data.length; i++) {
                                        $('#kit-products').append('<option qty_per_unit= '+ data[i]['qty_per_unit'] +' unit_type = '+ data[i]['unit_type'] + ' measure_unit = '+ data[i]['measure_unit'] +' product-price = ' + data[i]['purchase_price'] + ' value = ' + data[i]['id_business_products'] + '>' + data[i]['id_business_products'] + '-' + data[i]['product'] + ' ' + data[i]['category'] +' ' + data[i]['qty_per_unit'] +' ' + data[i]['measure_unit'] + ' ' + data[i]['sku'] + ' ' + data[i]['barcode_products'] +'</option>');
                                        //$('#productedit').append('<option product-price = ' + data[i]['purchase_price'] + ' value = ' + data[i]['id_business_products'] + '>' + data[i]['product'] + '</option>');
                                    }
                                } else {
                                    $('#kit-products').append('<option value = ""></option>');
                                    //$('#productedit').append('<option value = ""></option>');
                                }
                            }
                        });
                        $("#kit-products").select2();
                        $(".loader").fadeOut("slow");
                    }
                });
            
        });
        
        
        
        function openaddnew(){
            $('#addkit').modal('show');
        }
        
        function openaddproducts(kitid){
            $('#addkitproducts_kitid').html(kitid);
            $('#kit_id').val(kitid);
            $("#kit_qty").val('0');
            $("#unit_qty").val('0');
            $('#addkitproducts').modal('show');
        }
        

        function remove(kitconfigid){
            
            swal({
                title: "Are you sure?",
                text: "You want to remove this product!",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: '#DD6B55',
                confirmButtonText: 'Yes, I am sure!',
                cancelButtonText: "No, cancel it!",
                closeOnConfirm: true,
                closeOnCancel: true
            },
            function(isConfirm) {
                if(isConfirm){
                     
                    $.ajax({
                        type: "POST",
                        url: "<?php echo base_url(); ?>productkits_controller/remove_kit_products",
                        data: {
                                kit_config_id: kitconfigid                          
                            },
                        success: function(data) {
                           // console.log(data);
                            var result = data.split("|");
                            if (result[0] === "success") {
                                toastr.success('Product Removed!', 'Done!');
                                location.reload();
                            } else {
                                swal({
                                    title: "Error",
                                    text: 'Product not removed!',
                                    type: "error",
                                    confirmButtonText: 'OK!'
                                });
                            }
                        }
                    });
                }
            });
            
        }
        
        function openupdate(kitid){

            $.ajax({
                type: 'POST',
                url: '<?php echo base_url(); ?>product_controller/edit_product',
                data: {id_business_products: kitid},
                dataType: "json",
                cache: false,
                async: true,                    
                success: function(data) {
                   //console.log(data);
                    //var d= $.toJSON(data);
                   $("#editkitid").val(data.id_business_products);                   
                   $("#editbrandid").select2("val", data.brand_id);
                   $("#editproduct").val(data.product);
                   $("#editcategory").val(data.category);
                   $("#editprofessional").val(data.professional);
                   $("#editsku").val(data.sku);
                   $("#editcommission").val(data.commission);
                   $("#editpurchaseprice").val(data.purchase_price);
                   $("#editprice").val(data.price);
                   $("#editbarcode").val(data.barcode_product);
                   $("#editproducttype").val(data.product_type);
                   $("#editunittype").val(data.unit_type);
                   $("#editmeasurementunit").val(data.measure_unit);
                   $("#editqtyperunit").val(data.qty_per_unit);
                   $("#editthreshold").val(data.product_threshold);
                   
                   $('#editkit').modal('show');
                   
                }
            });
        
        }
        
    </script>