<?php 
error_reporting(0);
?>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="datatable/data.css">
<script src="datatable/data.js" type="text/javascript"></script>
<script src="datatable/table.js" type="text/javascript"></script>
<script src="datatable/datatable.js"></script>
<link rel="stylesheet" href="datatable/data-boot.css">
<link href="javascript/select2.css" rel="stylesheet" >
<script src="javascript/selectt2.js"></script>
<script src="restriction/editratemaster.js"></script>
<style>
    
    #navbar
    {
        flex:15%;
        height:100%; 
        flex-direction:row;

        
    }
    body
{
    counter-reset: Serial;           /* Set the Serial counter to 0 */
}
    #pricetable tr td:first-child:before
{
  counter-increment: Serial;      /* Increment the Serial counter */
  content:  counter(Serial); /* Display the counter */
}
    #content
    {
        flex:90%;
        overflow:auto;
        padding-left:10px;
        padding-right:10px;
    }
    #fullbody
    {
        display:flex;
        
         height:100%;         
    }
    label
    {
      font-size:20px;
    }
    .edit
    {
        font-size:18px;
        color:green;
        cursor:pointer;
    }
    .dele
    {
        font-size:18px;
        color:red;
        cursor:pointer;
    }
    .edit:hover
    {
        font-size:20px;
        
    }
    .dele:hover
    {
        font-size:20px;
        color:red;
        cursor:pointer;
        
    }
    td,th
    {
      text-align:center;
    }
    th
    {
      text-align:center;
    }
    li a 
    {
      color:black;
    }
    .page-item.active .page-link {
    
    background-color:yellow;
    border-color: #007bff;
}
    @media (max-width: 800px) {
        #fullbody
    {
        display:flex;
        flex-wrap: wrap;
                 
    }
        #navbar,#content {
    flex: 100%;
  }
}
</style>
<script>
$(document).ready( function () {
    $('#protable').DataTable();
} );
</script>

</head>
<body>
    
    <div id="fullbody"> 
<div id="navbar" class="bg-info"><?php include "navbar.php"?></div>
<div id="content">
<br>
<h3>Adjust-Rate</h3>
<br>
<!-- entry area -->
<?php 
$edi=$_GET['edit'];
$rateedit=mysqli_query($connect,"select  *, max(date),(select customerdetails.name from customerdetails where customerdetails.code = customerrate.customer && status!='deleted') as name from customerrate where status !='deleted' && customer ='$edi'");
while($rateshowedi = mysqli_fetch_array($rateedit))
{
  
?>
<form action="updaterate.php" method="post">
<div class="row">
              <div class="col-sm-3"><label>Date</label></div>:
              <div class="col-sm-6"><input type="date"  value="<?php echo date('d-m-Y') ?>"class="form-control"style="height:30px"  autocomplete="off" name="date" id="datemaster"placeholder="Date"></div>
              
            </div><br>
            <!--  -->
            <div class="row">
              <div class="col-sm-3"><label>Customer Name</label></div>:
              <div class="col-sm-6">
                
                <select class=" selectpro" name="customername" readonly>
              
                  <option value="<?php echo $rateshowedi['customer'] ?>"><?php echo $rateshowedi['name'] ?></option>
                  <!-- <?php 
                 $customer= $rateshowedi['customer'];
$proshow=mysqli_query($connect,"select * from customerdetails where code !='$customer' && status !='deleted'");
while($proshowshow = mysqli_fetch_array($proshow))
{
?>
<option value="<?php echo $proshowshow['code'] ?>"><?php echo $proshowshow['name'] ?></option>

<?php
}
?> -->
<script>
  $(document).ready(function(){
    $(".subspin").hide();
    $(".subspin2").hide();
$(".submit").click(function(){
$(".subspin").show();
});
$("#addprice").click(function(){
$(".subspin2").show();
$(".subspin2").hide();
});
setInterval(()=>{
  $.ajax({
            type:'POST',
            url:'ajaxpath1/fetch_date_time.php',
            success:function(data){
            console.log(data);
            var output = data.split("||");
            $("#dateProduct").val(output[0]);
            $("#timeProduct").val(output[1]);
                        }
           });  
  },1000);
})

</script>
                </select>
              </div>
            </div><br>
            <div class="row">
              <div class="col-sm-3"><label>Date</label></div>:
              <div class="col-sm-3"><input type="text" class="form-control" id="dateProduct" style="height:30px;"  placeholder="Date"></div>
              <div class="col-sm-1"><label>Time</label></div>:
              <div class="col-sm-3"><input type="text" class="form-control" id="timeProduct" style="height:30px;"  placeholder="Time"></div>
            </div><br>
            <!--  -->
            
            <div class="row">
              <div class="col-sm-2"><label>Product Name</label></div>:
              <div class="col-sm-3">
                
                <select class=" selectpro" name="productname" id="product">
                  <option>--Choose Product--</option>
                  <?php 
$cus=mysqli_query($connect,"select * from productdetail where status !='deleted'");
while($cusshow = mysqli_fetch_array($cus))
{
?>
<option value="<?php echo $cusshow['productcode'] ?>"><?php  echo $cusshow['productname'] ?></option>
        <?php }?>          
                </select>
                <input type="hidden" id="productname" class="form-control" style="height:30px;" autocomplete="off" name="price" placeholder="productname">
                <script>
                $(document).ready(function(){
                    $("#product").on('change',function(){
                       var pro = $(this).val();
                       $.ajax({
                      type:'POST',
                      url:'productnamefetch.php',
                      data:{pro:pro},
                      success:function(a){
                      //  alert(a);
                       // $("#showquantity-with-color").css("display","block");
                        $("#productname").val(a);
                        //alert(a);

                     }
                                  });
                    });
                });
              </script>
              <script>
                $(document).ready(function(){
                    $("#product").on('change',function(){
                       var pro = $(this).val();
                       $.ajax({
                      type:'POST',
                      url:'productpricefetch.php',
                      data:{pro:pro},
                      success:function(a){
                      //  alert(a);
                       // $("#showquantity-with-color").css("display","block");
                        $("#price").val(a);
                        $("#addprice").prop("disabled",false);
                        //alert(a);

                     }
                                  });
                    });
                });
              </script>
              </div>

              <div class="col-sm-1"><label>Price</label></div>:
              <div class="col-sm-2"><input type="text" class="form-control" id="price" style="height:30px;" autocomplete="off" name="price" placeholder="price-Gst"></div>
              <div class="col-sm-2"><input type="text" class="form-control" id="priceEst" style="height:30px;" autocomplete="off" name="priceest" placeholder="price-Est"></div>
              <div class="col-sm-1"><input type="button" class="btn btn-info" id="addprice" style="float:left;margin-left:10px;" value="+ Add"></div>
            </div><br>
            <!--  -->
            
            
<br><br>
<script>
$(document).ready(function(){       
  $(".alertbutton").hide();
       
  $("#product").on('change',function() {
          var pro = $("#product").val();
  //alert(pro);
         $(".procode").each(function(){
                var procode= $(this).val();
                if(pro == procode)
                {
                  
                  $("#price").prop("disabled",true);
                  $(".alertbutton").click();
                  $("#product").val(null).trigger("change");
                       $("#product").select2("open");
                       
                }
                else
                {
                  $("#price").prop("disabled",false); 
                }
                
         });
         });
              
          });

</script>
<!-- alert5 -->
<button type="button" class="btn btn-primary alertbutton" data-toggle="modal" data-target="#myModal">
      </button>

  <!-- The Modal -->
  <div class="modal fade" id="myModal">
    <div class="modal-dialog modal-lg">
     <div class="alert alert-danger alert-dismissible fade show">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <strong> Item Was Already Selected</strong>
  </div>
  </div>
        </div>
<!-- alert -->
            <!-- entry div over  -->
            <script type="text/javascript">
$(document).ready(function(){       
  
  $("#addprice").click(function() {
    var date = $("#date").val();
    var customer=$("#customer").val();
    var product = $("#product").val();
    var price = $("#price").val();
    var priceEst = $("#priceEst").val();
    var productname = $("#productname").val();
    var date = $("#dateProduct").val();
    var time = $("#timeProduct").val();
    
    //alert(date);
    $("#addprice").attr("disabled","disabled");
            //var acr = $("#acr").val();
            //var markup = "<tr><td><input type='checkbox' name='record'></td><td>" + patta + "</td><td>" + sur_no + "</td><td>" + hectare + "</td><td>" + acr + "</td></tr>";
            var markup = '<tr><td></td><td>'+product+'<input type="hidden" class="procode" name="product[]" value="'+product+'"></td><td>'+date+'<input type="hidden" name="productdate[]"  value="'+date+'"></td><td>'+time+'<input type="hidden" name="producttime[]"  value="'+time+'"></td><td>'+productname+'<input type="hidden" name="productname[]"  value="'+productname+'"><input type="hidden" name=""  value="'+date+'"></td><input type="hidden" name=""  value="'+date+'"></td><td>'+price+'<input type="hidden" name="price[]"  value="'+price+'"></td><td>'+priceEst+'<input type="hidden" name="priceest[]"  value="'+priceEst+'"></td><td><i class="fas fa-trash-alt dele"></i></td></tr>';
           
            $("#pricetable").append(markup);
           
            $("#product").val(null).trigger("change");
    // $("#product").select2("open");
     $("#price").val("");
     $("#priceEst").val("");
     $("#productname").val("");
     
     //$("#sales-add-product-with").attr("disabled","disabled");
     
    
        });
        $(document).on("click", ".dele", function(){

var del = $(this).parent().parent().remove();

});

  
  }); 
   
</script>
                <!-- modal for add confirm -->
<div class="modal fade" id="addpro">
    <div class="modal-dialog modal-sm">
      <div class="modal-content" style="background-color:rgba(77, 219, 106,0.9)">
      
        <!-- Modal Header -->
        
        
        <!-- Modal body -->
        <div class="modal-body">
          <span style="color:white"><i class="fas fa-check" style="font-size:24px"></i> Rate Have Been Adjusted Successfully</span>
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="" type="button" class="btn btn-warning submit" ><span class="spinner-border spinner-border-sm subspin2"></span>&nbsp Ok</button>
        </div>
        
      </div>
    </div>
  </div>
  
<!-- modal for add confirm -->
        <!--overall entry div over  -->
        <!-- tale -->
        <div class="entrytable" style="overflow:auto;max-width:100%">
    <table class="table table-bordered table-hover " id="pricetable" >
        <thead style="background-color:rgba(247, 191, 5,0.7)">
<tr>
<th>S.no</th>
<th>Name</th>
<th>Date</th>
<th>Time</th>
<th>Product</th>
<th>Price-Gst</th>
<th>Price-Est</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr>
<?php 
$proedit=mysqli_query($connect,"select * from customerrate where customer = '$edi' && status !='deleted'");
while($proshowedi = mysqli_fetch_array($proedit))
{
?>
<tr>
  <td></td>
  <td><input type="text" readonly class="procode" name="product[]" value="<?php echo $proshowedi['productcode'] ?>" style="border:none;outline:none;text-align:center"></td>
  
  <td><input type="text" readonly  name="productdate[]" value="<?php echo $proshowedi['date'] ?>" style="border:none;outline:none;text-align:center"></td>
  <td><input type="text" readonly name="producttime[]" value="<?php echo $proshowedi['edittime'] ?>" style="border:none;outline:none;text-align:center"></td>
  <td><input type="text" readonly name="productname[]"  value="<?php echo $proshowedi['productname'] ?>" style="border:none;outline:none;text-align:center"><input type="hidden" name=""  value="'+date+'"></td>
  <td><input type="text" readonly name="price[]" value="<?php echo $proshowedi['price'] ?>" style="border:none;outline:none;text-align:center"> </td><td><input type="text"  name="priceest[]" value="<?php echo $proshowedi['price_est'] ?>" style="border:none;outline:none;text-align:center"> </td><td><i class="fas fa-trash-alt dele"></i></td></tr>
</tr>
<?php 
}
?>
</tbody>
    </table>
</form>
</div>
        <!-- tale -->
        <input type="button" class="btn btn-success" value="Update" data-toggle="modal" id="submitbut" data-target="#addpro" >
    </div>
    <?php
}
    ?>
<!-- entry area over -->
</div>
<script>
    $('.selectpro').select2({ width: '100%',height:'420px;' });
    
</script>
<script>
  $(document).ready(function(){
    $(".subspin").hide();
    $(".subspin2").hide();
$(".submit").click(function(){
$(".subspin2").show();
});
$("#addprice").click(function(){
$(".subspin2").show();
$(".subspin2").hide();
});
  });
</script>
</body>
</html>