<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/ratemaster.js"></script>

<style>
    
    #navbar
    {
        flex:15%;
        height:100%; 
        flex-direction:row;
        overflow:auto;
        
    }
    body
{
    counter-reset: Serial;           /* Set the Serial counter to 0 */
}

    #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;
    }
    .delete
    {
        font-size:18px;
        color:red;
        cursor:pointer;
    }
    .edit:hover
    {
        font-size:20px;
        
    }
    .delete:hover
    {
        font-size:20px;
        color:red;
        cursor:pointer;
        
    }
    td
    {
      text-align:center;
    }
    th
    {
      text-align:center;
    }
    li a 
    {
      color:black;
    }
    .page-item.active .page-link {
    
    background-color:yellow;
    border-color: #007bff;
}
#pricetable tr td:first-child:before
{
  counter-increment: Serial;      /* Increment the Serial counter */
  content:  counter(Serial); /* Display the counter */
}
    @media (max-width: 800px) {
        #fullbody
    {
        display:flex;
        flex-wrap: wrap;
                 
    }
        #navbar,#content {
    flex: 100%;
  }
}
</style>
<script>
$(document).ready( function () {
    $('#protable').DataTable();
} );
</script>
<script>$('.datepicker').datepicker({
  inline: true
});</script>

</head>
<body>
    
    <div id="fullbody"> 
<div id="navbar" class="bg-info"><?php include "navbar.php"?></div>
<div id="content">
<br>
<h3>Rate-Master</h3>
<br>

<!-- table -->
<div>
  <!-- tab for rate -->
  <?php 
        $userall=$_SESSION['log'];
        $usper = mysqli_query($connect,"select * from userpermission where username = '$userall'  && filename='customerratemaster'");
while($per=mysqli_fetch_array($usper))
{
          ?>
  <ul class="nav nav-pills" role="tablist">
    <li class="nav-item">
      <a class="nav-link active" data-toggle="pill" href="#home">List</a>
    </li>
    <?php if($per['dataadd'] =='1'){ ?><li class="nav-item">
      <a class="nav-link" data-toggle="pill" href="#menu1">Entry</a>
    </li><?php }?>
    
  </ul>

  <!-- Tab panes -->
  <div class="tab-content" style="border:1px solid lightgrey">
    <!--  -->
    <div id="home" class="container tab-pane active"><br>
    <table class="table table-bordered table-hover " style="border:1px solid lightgrey" id="protable">
    <thead style="background-color:rgba(247, 191, 5,0.7)">
<tr>
    <th>Date</th>
    <th>Customer Name</th>
    <th>Product Count</th>
    
    <?php if($per['dataedit'] =='1'){ ?> <th>Edit</th><?php }?>
    <?php if($per['datadelete'] =='1'){ ?> <th>Delete</th><?php }?>
</tr>

    </thead>
    <tbody>
    <?php 
$proshow=mysqli_query($connect,"select max(date) as date,(select customerdetails.name from customerdetails where customerdetails.code = customerrate.customer && status !='deleted') as name,count(productcode)as count,customer from customerrate where status !='deleted' group by customer");
while($proshowsho = mysqli_fetch_array($proshow))
{
  $datechk=$proshowsho['date'];
  $dateval = date_create($datechk);
  $date = date_format($dateval,"d-m-Y");
?>
        <tr>
        <td><?php echo $date?></td>
    <td><?php echo $proshowsho['name'] ?></td>
    <td><?php echo $proshowsho['count'] ?></td>
    
    <?php if($per['dataedit'] =='1'){ ?> <td><a href="editcustomerrate.php?edit=<?php echo $proshowsho['customer'] ?>"><i class="fas fa-edit edit"></i></a></td><?php }?>
            <?php if($per['datadelete'] =='1'){ ?>   <td><a data-toggle="modal" data-target="#delete<?php echo $proshowsho['customer'] ?>"><i  class="fas fa-trash-alt delete"></a></i></td><?php }?>
        </tr>
        <?php }}?>
    </tbody>



</table>

<script type="text/javascript">
         $(function () {
             $('#datetimepicker1').datetimepicker();
         });
      </script>
    </div>
    <!-- entrydiv -->
    <div id="menu1" class="container tab-pane fade"><br>
    <!--  -->
    <form action="insertrate.php" method="post">
    <div class="row">
              <div class="col-sm-3"><label>Date</label></div>:
              <div class="col-sm-5">
                <!-- date -->
                <input type="date" class="formcontrol" name="date" id="datemaster">

            <!-- date -->
            </div>
              
            </div><br>
            <!--  -->
            <?php 
                 
$proshow=mysqli_query($connect,"select * ,max(date) from customerrate where  status !='deleted' group by customer");
while($proshowshow = mysqli_fetch_array($proshow))
{
?>
<input type="hidden" class="customerchk" value="<?php echo $proshowshow['customer'] ?>">
<?php
}
?>
<script>
$(document).ready(function(){       
  $(".alertbutton2").hide();
       
  $("#customer").on('change',function() {
          var cus = $("#customer").val();
  //alert(pro);
         $(".customerchk").each(function(){
                var cuscode= $(this).val();
                if(cus == cuscode)
                {
                  
                  $("#price").prop("disabled",true);
                  $(".alertbutton2").click();
                  $("#customer").val(null).trigger("change");
                       $("#customer").select2("open");
                }
                else
                {
                  $("#price").prop("disabled",false); 
                }
                
         });
         });
              
          });

</script>
<!-- alert5 customer -->
<button type="button" class="btn btn-primary alertbutton2" 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-warning alert-dismissible fade show">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <strong>Price Have Been Already Customized,Please Choose and Edit In List For This Customer!</strong>
  </div>
  </div>
        </div>
<!-- alert customer-->
            <div class="row">
              <div class="col-sm-3"><label>Customer Name</label></div>:
              <div class="col-sm-6">
                
                <select class=" selectpro" id="customer" name="customername">
                  <option>--Choose customer--</option>
                  <?php 
$cus=mysqli_query($connect,"select * from customerdetails where status !='deleted'");
while($cusshow = mysqli_fetch_array($cus))
{
?>
<option value="<?php echo $cusshow['code'] ?>"><?php  echo $cusshow['name'] ?></option>
        <?php }?>          
                </select>
              </div>
            </div><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");
                       $("#addprice").prop("disabled",false);
                }
                else
                {
                  $("#price").prop("disabled",false); 
                  $("#addprice").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 -->
            <!--  -->
            <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();
    //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>'+productname+'<input type="hidden" name="productname[]"  value="'+productname+'"><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>

<script>
  $(document).on('select2:open', () => {
    document.querySelector('.select2-search__field').focus();
  });
</script>
<script>
  $(document).ready(function(){
    $("#price").keyup(function(){
var value=$(this).val();
if (value = "")
{
  $("#addprice").attr("disabled","disabled");
}else
{
  $("#addprice").prop("disabled",false);
}

});
  });
  </script>
            <div class="row">
              <div class="col-sm-2"><label>Product Name</label></div>:
              <div class="col-sm-3">
                
                <select class=" selectpro" id="product" name="productname">
                  <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">
              </div>
              <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);
                        //alert(a);

                     }
                                  });
                    });
                });
              </script>
              <div class="col-sm-1"><label>Price</label></div>:
              <div class="col-sm-2"><input type="text" id="price" class="form-control" style="height:30px;" autocomplete="off" name="price" placeholder="price Gst"></div>
              <div class="col-sm-2"><input type="text" id="priceEst" class="form-control" 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" value="Add">
            <!-- spin -->
            <div class="spinner-grow spinner-grow-sm text-danger subspin2"></div>
<div class="spinner-grow spinner-grow-sm text-primary subspin2"></div>

            <!-- spin -->
            </div>
            </div><br>

            <!-- tale -->
        <div class="entrytable">
          <!-- card for entry -->
        <div class="card bg-light text-dark" style="max-height:250px;overflow:auto">
          <!--  -->
    <div class="card-body">
      <!-- entry -->
      <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>Product Code</th>
<th>Product</th>
<th>Price-Gst</th>
<th>Price-Est</th>
<th>delete</th>
</tr>
</thead>
<tbody>

</tbody>
    </table>
    <!-- entry  -->
</div>
<br>
  
<!--  -->
  </div><br>
  <input type="button" class="btn btn-success" data-toggle="modal" data-target="#addpro" style="float:left;margin-left:10px;" id="submitbut" value="Submit"><br>
</div>
<br>

<!-- card for entry -->

              </div>
</div><br>
        <!-- tale -->
        
            <!--  -->
            
            
<br><br>
            <!-- entry div over  -->
        </div>
                <!-- 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="submit"  type="button" class="btn btn-warning submit" > <span class="spinner-border spinner-border-sm subspin"></span> &nbspOk</button>
        </div>
        
      </div>
    </div>
  </div>
              </form>
  <script>
  $(document).ready(function(){
    $(".subspin").hide();
    $(".subspin2").hide();
$(".submit").click(function(){
$(".subspin").show();
});
$("#addprice").click(function(){
$(".subspin2").show();
$(".subspin2").hide();
});
  });
</script>
<!-- modal for add confirm -->
        <!--overall entry div over  -->
        
        
    </div>
   <!--  -->
  </div>
</div>
  <!-- tab for rate -->
</div>
<!-- tab for entry area-->

      
<!-- modal for delete -->
<!-- The Modal -->
<?php 
                 
$prodel=mysqli_query($connect,"select * ,max(date) from customerrate where  status !='deleted' group by customer");
while($prodelshow = mysqli_fetch_array($prodel))
{
?>

<div class="modal fade" id="delete<?php echo $prodelshow['customer'] ?>">
    <div class="modal-dialog modal-sm">
      <div class="modal-content" style="background-color:rgba(247, 2, 80,0.9)">
      
        <!-- Modal Header -->
        <form action="deleterate.php" method="post">
        <input type="hidden"  name="delete" value="<?php echo $prodelshow['customer'] ?>">

        <!-- Modal body -->
        <div class="modal-body" >
         Are You Sure Want To Delete !.
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
        <button type="submit" class="btn btn-success">Yes</button></a>
          <button type="button" class="btn btn-warning" data-dismiss="modal">No</button>
</form>
        </div>
        
      </div>
    </div>
  </div>
  <?php
}
?>
<!-- ,odal for delete -->
<!-- table -->


<!-- main-content-div -->
</div>
<!-- main-content-div -->
</div>
<script>
    $('.selectpro').select2({ width: '100%',height:'420px;' });
    
</script>





</body>