<?php 


require_once("config/configDB.php"); 
require "userPermission.php";

$sql_customer = mysqli_query($conn,"SELECT id,cname FROM customer_master WHERE isdelete='1' ");
$row_customer = '';

while($crow = mysqli_fetch_array($sql_customer)){

    $row_customer =$row_customer."<option value='".$crow['id']."'>".$crow['cname']."</option>";

}


$sqlproduct = mysqli_query($conn,"SELECT id, productname FROM product_master WHERE isdelete='1' ");

$sql_product = '';

while($prow = mysqli_fetch_array($sqlproduct)){

    $sql_product =$sql_product."<option value='".$prow['id']."'>".$prow['productname']."</option>";

}

?>
<!DOCTYPE html>
<html>
<head>
    <title>Product Sale price</title>
    <?php require 'header.php' ?>
    

</head>
<body>
    <?php require 'menu.php' ?>
<div class="container-fluid">
<h2 class="text-center"> Customer Based Rate for  Sales Products </h2><br>
    <form class="form-horizontal" action="productsalepriceInsert.php" method="post">
 
    
  

<div class="container">

<table id="mappingProduct" class="table  table-striped table-bordered dt-responsive" style="overflow-x:auto;"  >
        <thead>
            <tr>
                <th>Customer Name </th>
                <th>Product Name </th>
                <th>MRP</th>
                <th>Customer Price</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            <tr>
            <td><select class="form-control" name="customer" >
        <option value="">Select the Customer </option>
        <?php echo  $row_customer; ?>
        </select></td>
            <td><select class="form-control product-select-box" name="product" >
        <option value="">Select the Product </option>
        <?php echo  $sql_product; ?>
        </select>
        </td>
        <td><input class="form-control" type="text" id="pur_rate" name="pur_rate" readonly></td>
        <td><input class="form-control" type="text" id="sale_rate" name="sale_rate" required></td>
        
        
        <td><button type="submit" class="btn btn-default">Update</button></td>
            </tr>
           
        </tbody>
       
    </table>
    
</div>

</form>   
</div>


<div class="container-fluid col-sm-12">

<!-- productcode, productname, purchase_rate, gst, hsn_code,prodct_description, create_date -->

<table id="productSalePriceDashboard" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>ProductID</th>
                <th>Customer Name</th>
                <th>Product Code</th>
                <th>Product Name</th>
                <th>MRP </th>
                
                <th>Customer Price</th>
               
                
            </tr>
        </thead>
        <tbody>

                    
           
        </tbody>
       
    </table>
    
</div>





    <?php require 'footer.php' ?>
    <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
    <script type="text/javascript" language="javascript" src="js/productMapping.js"></script>

    <script>
    
    $(document).ready(function() {
                   var dataTable =  $('#productSalePriceDashboard').DataTable( {
                           responsive: {
                        details: {
                            renderer: function ( api, rowIdx ) {
                            var data = api.cells( rowIdx, ':hidden' ).eq(0).map( function ( cell ) {
                                var header = $( api.column( cell.column ).header() );
                                return  '<p style="color:#00A">'+header.text()+' : '+api.cell( cell ).data()+'</p>';
                            } ).toArray().join('');
     
                            return data ?    $('<table/>').append( data ) :    false;
                            }
                        }
                        },
                       processing: true,
                    serverSide: true,
                    //ajax: "test.js", // json datasource
                    ajax: "productSalePricegriddata.php",
                    } );
                } );
    
    </script>
</body>
</html>