<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
    <title>View Lead</title>
  </head>
  <body>
    <div class="container">
     <h1>View Lead</h1>
     <p>
		<form>
          <div class="form-group">
            <label for="exampleFormControlInput1">Lead Code</label>
            <input type="text" class="form-control" name="lead_code" id="lead_code" value="" readonly="readonly">
          </div>
          <div class="form-group">
            <label for="exampleFormControlInput1">By</label>
            <input type="text" class="form-control" name="by" id="by" value="" readonly="readonly">
          </div>
          <div class="form-group">
            <label for="exampleFormControlInput1">What</label>
            <input type="text" class="form-control" name="what" id="what" value="" readonly="readonly">
          </div>
          <div class="form-group">
            <label for="exampleFormControlInput1">When</label>
            <input type="text" class="form-control" name="when" id="when" value="" readonly="readonly">
          </div>
          <div class="form-group">
            <label for="exampleFormControlInput1">Where</label>
            <input type="text" class="form-control" name="where" id="where" value="" readonly="readonly">
          </div>
          <div class="form-group">
            <label for="exampleFormControlInput1">Customer Ask Price</label>
            <input type="text" class="form-control" name="customer_ask_price" id="customer_ask_price" value="" readonly="readonly">
            <input type="hidden" name="id" id="id" value="">
          </div>
          <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">Convert to Quote</button>
        </form>
      </p>
    </div>
    <!-- Modal -->
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Convert to Quote</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
           		<form>
                  <div class="form-group">
                    <label for="exampleFormControlInput1">Quoted Price</label>
                    <input type="text" class="form-control" name="quoted_price" id="quoted_price" value="" >
                  </div>
                </form>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary btn_save">Save changes</button>
          </div>
        </div>
      </div>
    </div>
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
  <script>
  $(document).ready(function() {
	   $.ajax({
		  method: "POST",
		  url: "http://192.168.33.10/gopi_app/get_lead.php",
		  dataType: "json",
		  data: { id: <?php echo $_GET['id'] ?> }
		})
		  .done(function( json ) {
		    $("#id").val(json.id);
		    $("#lead_code").val(json.lead_code);
		    $("#by").val(json.by);
		    $("#what").val(json.what);
		    $("#when").val(json.when);
		    $("#where").val(json.where);
		    $("#customer_ask_price").val(json.customer_ask_price);
		  });
	   $( ".btn_save" ).click(function() {
		   var quote_price = parseFloat($("#quoted_price").val());
		   //if(quote_price != "NaN") {
		   $.ajax({
				  method: "POST",
				  url: "http://192.168.33.10/gopi_app/create_quote.php",
				  dataType: "json",
				  data: { lead_id: <?php echo $_GET['id'] ?> , quote_price: quote_price }
				})
				  .done(function( json ) {
					  $('#exampleModal').modal('toggle');
				  });
		   //}
	   });
  });
  </script>
  </body>
</html>