<?php
session_start();

if($_SESSION['name']==''){
    header("Location:index.php");die();
}

?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
  <!-- Morris chart -->
  <link rel="stylesheet" href="bower_components/morris.js/morris.css">
  <!-- jvectormap -->
  <link rel="stylesheet" href="bower_components/jvectormap/jquery-jvectormap.css">
  <!-- Date Picker -->
  <link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
  <!-- Daterange picker -->
  <link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
  <!-- bootstrap wysihtml5 - text editor -->
  <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

  <!-- Google Font -->
  <link rel="stylesheet" href="bower_components/datatables/css/dataTables.bootstrap.min.css">
  <link rel="stylesheet" href="bower_components/datatables/css/dataTables.bootstrap.css">
  
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="bower_components/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->

<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Morris.js charts -->

<!-- Sparkline -->
 <script src="vendor/datatables/jquery.dataTables.js"></script>
    <script src="vendor/datatables/dataTables.bootstrap4.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<!--<script src="dist/js/pages/dashboard.js"></script>-->
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <?php include("header.php");?>
  <!-- Left side column. contains the logo and sidebar -->
  <aside class="main-sidebar">
    <!-- sidebar: style can be found in sidebar.less -->
    <?php include("sidebar.php");?>
    <!-- /.sidebar -->
  </aside>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
  

    <!-- Main content -->
    <section class="content">
      
        <div class="row">
            <div class="col-md-12">
          <!-- Custom Tabs -->
          <div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
<!--                 <li class=""><a href="#tab_11" data-toggle="tab">Invoice</a></li>-->
<!--              <li><a href="#tab_21" data-toggle="tab">View Hotel</a></li>-->
              <li class="active rm"><a href="#tab_11" data-toggle="tab">Customer Details</a></li>
            
            
             
             
            </ul>
            <div class="tab-content ">
                <div class="tab-pane active" id="tab_11">
<!--                     From:<input type='text' class='datepicker' id='from_date'>
                    to:<input type='text' class='datepicker' id='to_date'>-->
                      <button class='btn btn-primary' id="get_invoice">Refresh</button>
                      <br><br>
                        
                    
                    <table class='table' id='table1'>
                      <thead>
                          <tr><th>Sl No</th><th>Product Name</th>
<!--                          <th>Address1</th>
                           <th>Address2</th>
                            <th>Address3</th>
                             <th>Mobile</th>
                              <th>GST No</th>
                               <th>Email Id</th>
                          <th>Action</th>-->
                          </tr>
                      </thead>
                      
                  </table>   
              </div>
               <div class="tab-pane" id="tab_21">
                 
              </div>
                
           
            
              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_2">
                 
              </div>
              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_3">
               
              </div>
              <!-- /.tab-pane -->
            </div>
            <!-- /.tab-content -->
          </div>
          <!-- nav-tabs-custom -->
        </div>
            
            
        </div>
        
        
        
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
 
  <!-- /.control-sidebar -->
  <!-- Add the sidebar's background. This div must be placed
       immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<!-- jQuery 3 -->

</body>
</html>

<div id='edit_div' style="display:none">
    Customer Name:<br>
    <input type='text' id='edit_customer_name'>
    <br>
     Address1:<br>
    <input type='text' id='edit_adr1'>
    <br>
     Address2 :<br>
    <input type='text' id='edit_adr2'>
    <br>
     Address3 :<br>
    <input type='text' id='edit_adr3'>
    <br>
     Mobile:<br>
    <input type='text' id='edit_msisdn'>
    <br>
     GST No:<br>
    <input type='text' id='edit_gst'>
    <br>
    Email Id:<br>
    <input type='email' id='edit_email_id'>
    <br>
    <button class='btn btn-primary' id="update">Update</button>
</div>

<style>
    .required:before{
   color: red;
   content: "*";
   position: absolute;
font-weight:bold !important;font-size: 18px;
}
    
    
</style>
<script src="jquery-ui.js"></script>
<link href='jquery-ui.css' rel='stylesheet'>
<script src='notify.min.js'></script>
<script src='notify.js'></script>
<link href='chosen.css' rel='stylesheet'>

<script> tab= $("#table1").DataTable();
      function notify(data){
$.notify(data, "success");
    }
     function notify1(data){
$.notify(data, "error");
    }
//  $("#from_date").datepicker({ dateFormat: "yy-mm-dd"}).datepicker("setDate", "0");
//  $("#to_date").datepicker({ dateFormat: "yy-mm-dd"}).datepicker("setDate", "0");
//    
     $("#get_invoice").click(function(){
    from_date=$("#from_date").val();     
    to_date=$("#to_date").val();     
   status="";
get_cusomers(from_date,to_date);
  });
    
    
   function get_cusomers(from_date,to_date) {
      tab.destroy();
   
           tab= $("#table1").DataTable({
                  "processing": true,
        "serverSide": true,
        "bPaginate":true, // Pagination True
      "sPaginationType":"full_numbers", // And its type.
       "iDisplayLength": 10,
        "ajax": {
           //  "url": "get_completed_tests_for_print_backup.php",
           url:"get_product_details.php", 
   data:{from_date:from_date,to_date:to_date},
   type:"POST",
   dataType:"JSON",
   
           
            "dataSrc": function (json1) {
          var return_data=new Array(); 
          var data=json1.data;
          var k=1;
          for(var i=0;i<data.length;i++){
          
        
        return_data.push({
              
          'id':k++,
         "product_name":data[i].product_name,
//         "adr1":data[i].adr1,
//         "adr2":data[i].adr2,
//         "adr3":data[i].adr3,
//         "msisdn":data[i].msisdn,
//         "gst_no":data[i].gst_no,
//         "email_id":data[i].email_id,
//         "action":"<button class='btn btn-primary edit' value='"+data[i].quotation_no+"'>Edit</button>",
      
          
        });
       }
    $("#table1_filter").find("input").css({"width":"700px","margin-left":"-80%"});
       $("#table1_filter").find("input").attr("placeholder","Search Product Name");
      return return_data;
       }
    
        } ,
          "columnDefs": [
        { 
            "targets": [ 0,1], //first column / numbering column
            "orderable": false, //set not orderable
        },
        ],
        "columns": [
           { "data": "id" },
            { "data": "product_name" }
//               { "data": "adr1" },
//                   { "data": "adr2" },
//                   { "data": "adr3" },
//                   { "data": "msisdn" },
//                   { "data": "gst_no" },
//                    { "data": "email_id" },
//                    { "data": "action" },
//                     
               
        ]
   
             });
              
                                    
       
}
get_cusomers("","");


$("body").on("click",".edit",function(){
   
    var qtn=$(this).val()
    $.ajax({
       url:"get_edit_quotation.php",
       data:{qtn:qtn},
       type:"POST",
       dataType:"JSON",
       success:function(data1){
           var cust_data=data1.cust_data;
           
           
           
           
           
           
           $("#edit_customer_name").val(cust_data[0].customer_name);
            $("#edit_adr1").val(cust_data[0].adr1);
             $("#edit_adr2").val(cust_data[0].adr2);
              $("#edit_adr3").val(cust_data[0].adr3);
              $("#edit_msisdn").val(cust_data[0].msisdn);
              $("#edit_gst").val(cust_data[0].gst_no);
                $("#edit_email_id").val(cust_data[0].email_id);
                    $("#update").val(cust_data[0].quotation_no);
                
              $("#edit_div").dialog({"title":"Edit"});
      
   }
       
    });
});



$("#update").click(function(){

    var customer_name=$("#edit_customer_name").val();
    var adr1=$("#edit_adr1").val();
    var adr2=$("#edit_adr2").val();
     var gst_no=$("#edit_gst").val();
    var qtn=$(this).val();
      var msisdn=$("#edit_msisdn").val();
      var adr3=$("#edit_adr3").val();
       var email_id=$("#edit_email_id").val();
     if(customer_name==""||adr1==""||adr2==""||adr3==""||gst_no==""||msisdn==""||email_id==""){
         notify1("All * fields are mandatory");return false;
     }
     
     if(isNaN(msisdn)){
          notify1("Mobile should be  numeric");return false;
     }
    
    
      $.ajax({
      url:"update_customer.php",
      data:{qtn:qtn,adr3:adr3,msisdn:msisdn,customer_name:customer_name,adr1:adr1,adr2:adr2,gst_no:gst_no,email_id:email_id},
      type:"POST",
      dataType:"JSON",
      success:function(data1){
          notify(data1.data+ " Row Updated Successfully");
           $("#edit_div").dialog("close");
           
get_cusomers("","");
//        $("#table1 tbody").remove();
//        $("#tab_11 input").each(function(){
//            $(this).val("");
//               $(this).html("");
//               
//        })
         // get_pdf(data1.quotation_no,t1_base_price,t1_gst,t2_grand);
        //get_pdf(97);
      },
          error:function(xhr){
              notify1(xhr.responseText);
          }
   });
})



    </script>
    <style>
        #table1 thead tr {
    background: green;
    color: white;
}
        
    </style>