<?php
include "include/db.php";
include "include/auth.php";
if($user_type == 'admin'){
    $active_user_id = "admin_id = $admin_id,";
}elseif($user_type == 'staff'){
    $active_user_id = "employee_id = $employee_id,";
}
if((isset($_REQUEST['invoice_no']) && isset($_REQUEST['prop_case_num']) && isset($_REQUEST['prop_full_add']) && isset($_REQUEST['prop_state'])&& isset($_REQUEST['prop_city'])&& isset($_REQUEST['prop_zip'])&& isset($_REQUEST['new_invoice_client_name'])) || (isset($_REQUEST['invoice_no']) && isset($_REQUEST['prop_id'])&& isset($_REQUEST['new_invoice_client_name']))){

    if((strlen($_REQUEST['prop_case_num'])>0 && strlen($_REQUEST['prop_full_add'])>0 && strlen($_REQUEST['prop_state'])>0 && strlen($_REQUEST['prop_city'])>0 && strlen($_REQUEST['prop_zip'])>0)){
        $prop_case_num = trim($_REQUEST['prop_case_num']);
        $prop_loan_num = $prop_case_num;
        $prop_full_add = $_REQUEST['prop_full_add'];
        $prop_city = $_REQUEST['prop_city'];
        $prop_state = $_REQUEST['prop_state'];
        $prop_zip = $_REQUEST['prop_zip'];
        if(isset($_REQUEST['prop_county'])){
            if (strlen($_REQUEST['prop_county'])>0){
                $prop_county = $_REQUEST['prop_county'];
            }else{
                $prop_county = '';
            }
        
        }else{
            $prop_county = '';
        }        

        $time = date("Y-m-d H:i:s");

        $query_check_prop = "SELECT * FROM property WHERE (prop_case_num = '$prop_case_num' AND prop_loan_num = '$prop_loan_num') OR (prop_case_num = '$prop_case_num') OR (prop_loan_num = '$prop_loan_num')";

        $run_check_prop = mysqli_query($conn, $query_check_prop);

            if(mysqli_num_rows($run_check_prop) == 0){
                $query_prop_insert = "INSERT INTO property SET prop_case_num = '$prop_case_num', prop_loan_num = '$prop_loan_num', prop_full_add = '$prop_full_add', prop_city = '$prop_city', prop_state = '$prop_state', prop_zip = '$prop_zip', prop_county = '$prop_county', create_time = '$time', is_approve = 1, $active_user_id approve_time = '$time'";

                $run_prop_insert = mysqli_query($conn, $query_prop_insert);
                if(mysqli_affected_rows($conn) > 0){
                    $prop_id = mysqli_insert_id($conn);
                    $successmessage = "$prop_case_num has been added. Use it for new Work Order";
                    if(strlen($_REQUEST['new_invoice_client_name'])>0){
                        $p_client_id = $_REQUEST['new_invoice_client_name'];
                   
                        $time = date("Y-m-d H:i:s");
                    
                        $p_lot_size = '';
                        
                        $p_sf = $_REQUEST['p_sf']; 
                        
                        $p_bedroom = '';
                        
                        $p_bathroom = '';

                        $check1 = "SELECT * FROM prop_assign WHERE prop_id = $property_id AND client_id = $p_client_id";
                        $run_check1 = mysqli_query($conn, $check1);
                
                        if(mysqli_num_rows($run_check1) == 0){
                            $query_insert_prop_assign = "INSERT INTO prop_assign SET client_id = $p_client_id, prop_id = $prop_id, p_lot_size = '$p_lot_size', p_sf = '$p_sf', p_bedroom = '$p_bedroom', p_bathroom = '$p_bathroom', $active_user_id is_approve = 1, approve_time = '$time', create_time = '$time'";

                            $run_insert_prop_assign = mysqli_query($conn,$query_insert_prop_assign);
                
                
                            if(mysqli_affected_rows($conn) > 0){
                
                                $successmessage = "New Client Added to this property.";
                        
                            }else{
                                $message = "Something went wrong. Try Again";                            
                
                            }     
                            
                        }else{
                            $message = "That Client Already exists in this property ID";
                            
                        }

                    }
                    

                }
            }else{
                $message = 'That Property Case or Loan Number already exists.';

        }

    }

    if(isset($_REQUEST['prop_id'])){
        if(strlen($_REQUEST['prop_id'])>0){
            $prop_id = $_REQUEST['prop_id'];
        }
    }

    if(strlen($prop_id)>0 && strlen($_REQUEST['invoice_no'])>0 && strlen($_REQUEST['new_invoice_client_name'])>0){

        $invoice_no = trim($_REQUEST['invoice_no']);
        $new_invoice_client_name = $_REQUEST['new_invoice_client_name'];

        $time = date("Y-m-d H:i:s");

        $query_check_invoice = "SELECT * FROM invoice WHERE invoice_no = '$invoice_no'";

        $run_check_invoice = mysqli_query($conn, $query_check_invoice);

            if(mysqli_num_rows($run_check_invoice) == 0){
                $query_invoice_insert = "INSERT INTO invoice SET invoice_type = '1', invoice_no = '$invoice_no', client_id = $new_invoice_client_name, prop_id = $prop_id, create_time = '$time', is_approve = 1, invoice_amount = 0.00,$active_user_id approve_time = '$time'";

                $run_invoice_insert = mysqli_query($conn, $query_invoice_insert);
                if(mysqli_affected_rows($conn) > 0){
                    $invoice_id = mysqli_insert_id($conn);
                    header("Location:add-items-invoice.php?state=1&in_no=$invoice_id&client_id=$new_invoice_client_name&invoice_no=$invoice_no");
                }
            }else{
                $message = 'That Invoice Number already exists.';
        }
    }
}
include "header.php";
?>
<div id="page-wrapper">
<h4>Fill Invoice Details</h4>


                    <?php
                        if(isset($successmessage)){

                            echo '<div class="alert alert-success">
                            <strong>'. $successmessage .'</strong></div>';
                        }

                        if(isset($message)){
                            echo '<div class="alert alert-danger">
                            <strong>'. $message .'</strong>
                        </div>';
                        }
                    ?>

                    <style>
                    .autocomplete-suggestions { border: 1px solid #999; background: #FFF; overflow: auto; }
.autocomplete-suggestion { padding: 2px 5px; white-space: nowrap; overflow: hidden; }
.autocomplete-selected { background: #F0F0F0; }
.autocomplete-suggestions strong { font-weight: normal; color: #3399FF; }
.autocomplete-group { padding: 2px 5px; }
.autocomplete-group strong { display: block; border-bottom: 1px solid #000; }
                    </style>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                <!-- <div class="col-lg-12"> -->
                  <!--   <h3> -->

<form  action = "invoice.php" method = "POST" class = "form-group" enctype = "multipart/form-data">

    <div class = "row">

        <div class = "form-group col-lg-6">
            <label for="new_invoice_client_name1">Select Client</label>
            <input type="text" class='form-control' name='new_invoice_client_name1' id="new_invoice_client_name1" autofocus required='required' placeholder="Search for Client Name">
            <input type="hidden" class='form-control' name='new_invoice_client_name' id='new_invoice_client_name'>
        </div>
        <div class = "form-group col-lg-6">

        </div>
    </div>
    <div class="row">
        <div class = "form-group col-lg-6" id= "new_invoice_prop_column">

        </div>
        <div class = "form-group col-lg-6">

        </div>
    </div>
    <div id = "new_invoice_if_add">
    </div>
    <div id = "new_invoice_if_set">
    </div>
    <div id = "new_invoice_wo" style = "display:none">
        <div class="row">
            <div class = "form-group col-lg-6" id = "new_bid_wo_add">
               
            </div>
            <div class = "form-group col-lg-6">
            </div>


        </div>
        <div class="row">
            <div class = "form-group col-lg-6">
             <input type="submit" name = "submit" value = "Next" class="btn btn-success">
            </div>
            <div class = "form-group col-lg-6">
            </div>


        </div>

    </div>
</form>




                    <!-- </h3> -->
                </div><!-- head -->
            </div> <!--panel  -->
        </div><!--col 12  -->
    </div><!-- row -->
 </div> <!--  page wrapper -->



</div>

 <!-- jQuery -->
 <script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')</script>

<script>

function getNewInvoicePropValue(){
  var val1 = document.getElementById("new_invoice_client_name");
  val1 = val1.value; 
  if(typeof(val1) != 'undefined' || val1 != null){ 
    var elemxxxq = document.querySelector('#new_invoice_wo');
        
        elemxxxq.style.display = 'none';
      
    var data33 = '';
         $("#new_invoice_if_add").html(data33);   
        $.ajax({
        type: "POST",
        url: "get_new_invoice_client_prop.php",
        data:'cl_id='+val1,
        success: function(data){
            $("#new_invoice_prop_column").html(data);
        }
        });
    }  
}

function getNewInvoiceWOValue(){
  var val1 = document.getElementById("new_invoice_prop_id");
  val1 = val1.value; 
  if(typeof(val1) != 'undefined' || val1 != null){ 
    
      if(val1 == 'new'){
        var data91231 = '';
      
      $("#new_bid_wo_add").html(data91231);   
        var data3 = '';
         $("#new_invoice_if_set").html(data3);
      var data2 = '<div class = "row">'+
        
        '<div class = "form-group col-lg-6">'+
        '<label for="prop_case_num">Case/Loan Number</label>'+
        '<input type="text" class="form-control" name="prop_case_num" id="prop_case_num" value="<?php $prop_case_num =time().mt_rand (10,99); echo $prop_case_num; ?>" required="required" autofocus>'+
        '</div>'+'<div class = "form-group col-lg-6">  '+ '<label for="invoice_no">Invoice Number</label><input type="text" class="form-control" name="invoice_no" id="invoice_no" value="<?php $wo_num =mt_rand (10,99).time(); echo $wo_num; ?>" required="required" autofocus>'+'</div>'+
        ' </div>  '+      

      '  <div class = "row">      '+
    
    '<div class = "form-group col-lg-6">'+
    '  <div class="row">'+
' <div class="form-group col-lg-6">'+
'<label for="prop_zip">Zipcode</label>'+
'   <input type="text" class="form-control" maxlength="5" minlength="5" name="prop_zip" id="prop_zip" required="required">  '+                    

                '   </div>'+
    '    <div class="form-group col-lg-6">'+
    '          <label for="prop_city">City</label>'+
               

                   '    <input type="text" class="form-control" name="prop_city" id="prop_city" required="required">   '+ 

                 '  </div>'+
                
                  
               
                     ' </div>'+

             '  <div class="row">'+ '   <div class="form-group col-lg-6">'+
                 '  <label for="prop_county">County</label>'+
               

                     '  <input type="text" class="form-control" name="prop_county" id="prop_county">  '+
                   
                     '</div>'+

                  ' <div class="form-group col-lg-6">'+
                  '  <label for="prop_state">State</label>'+

                 '  <select class="form-control" name="prop_state"  id="prop_state" required="required">'+
                 ' <option value="" disabled="disabled" selected="selected">Select State</option>'+

'<option value="AL">Alabama</option>'+
'<option value="AK">Alaska</option>'+
'<option value="AZ">Arizona</option>'+
'<option value="AR">Arkansas</option>'+
'<option value="CA">California</option>'+
'<option value="CO">Colorado</option>'+
'<option value="CT">Connecticut</option>'+
'<option value="DE">Delaware</option>'+
'<option value="DC">District of Columbia</option>'+
'<option value="FL">Florida</option>'+
'<option value="GA">Georgia</option>'+
'<option value="HI">Hawaii</option>'+
'<option value="ID">Idaho</option>'+
'<option value="IL">Illinois</option>'+
'<option value="IN">Indiana</option>'+
'<option value="IA">Iowa</option>'+
'<option value="KS">Kansas</option>'+
'<option value="KY">Kentucky</option>'+
'<option value="LA">Louisiana</option>'+
'<option value="ME">Maine</option>'+
'<option value="MD">Maryland</option>'+
'<option value="MA">Massachusetts</option>'+
'<option value="MI">Michigan</option>'+
'<option value="MN">Minnesota</option>'+
'<option value="MS">Mississippi</option>'+
'<option value="MO">Missouri</option>'+
'<option value="MT">Montana</option>'+
'<option value="NE">Nebraska</option>'+
'<option value="NV">Nevada</option>'+
'<option value="NH">New Hampshire</option>'+
'<option value="NJ">New Jersey</option>'+
'<option value="NM">New Mexico</option>'+
'<option value="NY">New York</option>'+
'<option value="NC">North Carolina</option>'+
'<option value="ND">North Dakota</option>'+
'<option value="OH">Ohio</option>'+
'<option value="OK">Oklahoma</option>'+
'<option value="OR">Oregon</option>'+
'<option value="PA">Pennsylvania</option>'+
'<option value="RI">Rhode Island</option>'+
'<option value="SC">South Carolina</option>'+
'<option value="SD">South Dakota</option>'+
'<option value="TN">Tennessee</option>'+
'<option value="TX">Texas</option>'+
'<option value="UT">Utah</option>'+
'<option value="VT">Vermont</option>'+
'<option value="VA">Virginia</option>'+
'<option value="WA">Washington</option>'+
'<option value="WV">West Virginia</option>'+
'<option value="WI">Wisconsin</option>'+
'<option value="WY">Wyoming</option>'+
'</select>'+
'</div>'+

              ' </div>'+
           
           
              ' </div>    '+  
 ' <div class = "form-group col-lg-6">'+

    '   </div>   '+ ' </div>'+' <div class = "row">'+  
 ' <div class = "form-group col-lg-6">'+
 '     <label for="prop_full_add">Address</label> '+         
 '     <textarea rows="4" name="prop_full_add" class = "form-control" id="prop_full_add" placeholder=""  maxlength="5000"></textarea>  '+

    '   </div>   '+  
 ' <div class = "form-group col-lg-6">'+

    '   </div>   '+' </div>'; 


      $("#new_invoice_if_add").html(data2); 
      var elemxxx = document.querySelector('#new_invoice_wo');
        
        elemxxx.style.display = 'block';
      }else{
          var data3 = '';
         $("#new_invoice_if_add").html(data3);
         var val11 = document.getElementById("new_invoice_prop_id");
         val11 = val11.value;
         if(typeof(val11) != 'undefined' || val11 != null){   
       
        var data9 = '<input type = "hidden" name ="prop_id" value="'+val11 +'">';
      
        $("#new_invoice_if_set").html(data9);

        var elemxxx = document.querySelector('#new_invoice_wo');

        elemxxx.style.display = 'block';

         var data9123 = '<label for="invoice_no">Invoice Number</label><input type="text" class="form-control" name="invoice_no" id="invoice_no" value="<?php $wo_num =mt_rand (10,99).time(); echo $wo_num; ?>" required="required" autofocus>';
      
      $("#new_bid_wo_add").html(data9123);
        
    }

      }     


    }

    $("#prop_zip").keyup(function() {
    if($(this).val().length == 5) {
        $("#prop_zip").prop('disabled', true);
        $("#prop_city").prop('disabled', true);
        $("#prop_county").prop('disabled', true);
        $("#prop_state").prop('disabled', true);

        var n = $(this).val(); 
        $.ajax({
        type: "POST",
        url: "prop_zip_search_adata.php",
        data:'data='+n,
        success: function(data){
            data = data.trim(); 
            if(data == 'no'){
                $("#prop_zip").prop('disabled', false);
                $("#prop_city").prop('disabled', false);
                $("#prop_county").prop('disabled', false);
                $("#prop_state").prop('disabled', false);
                $('#prop_zip').trigger("reset");                
                $('#prop_city').trigger("reset");                
                $('#prop_county').trigger("reset");
                $('#prop_state').trigger("reset");                

            }else{                
                var data_response = JSON.parse(data);

                var state = data_response.state;
                var state_id = data_response.s_id;
                var city = data_response.city;
                var country = data_response.country;
                var status_res = data_response.status; 
                var county = data_response.county;

                if(status_res = 'yes'){
                    $("#prop_zip").prop('disabled', false);

                    if(city.length >1){
                        $('input[name="prop_city"]').val(city);
                        $("#prop_city").prop('disabled', false);

                    }else{
                        $('input[name="prop_city"]').val(state);
                        $("#prop_city").prop('disabled', false);
                        $('#prop_city').trigger("reset"); 
                    }

                    if(county.length >1){
                        $('input[name="prop_county"]').val(county);
                        $("#prop_county").prop('disabled', false);

                    }else{
                        $('input[name="prop_county"]').val(county);
                        $("#prop_county").prop('disabled', false);
                        $('#prop_county').trigger("reset"); 
                    }

                    if(state_id.length >1){
                        $("#prop_state").val(state_id);
                        $("#prop_state").prop('disabled', false);
                    }else{
                        $("#prop_state").prop('disabled', false);
                        $('#prop_state').trigger("reset"); 
                    }
                   

                }else{
                    $("#prop_zip").prop('disabled', false);
                    $("#prop_city").prop('disabled', false);
                    $("#prop_county").prop('disabled', false);
                    $("#prop_state").prop('disabled', false);
                    $('#prop_zip').trigger("reset");                
                    $('#prop_city').trigger("reset");                
                    $('#prop_county').trigger("reset");
                    $('#prop_state').trigger("reset");   
                }

            }
        }
    });
         
    }
});
  
}

function addAddress(){

     var data91234 = '';
      
      $("#new_bid_wo_add").html(data91234);
    var data2 = '<div class = "row">'+
        
        '<div class = "form-group col-lg-6">'+
        '<label for="prop_case_num">Case/Loan Number</label>'+
        '<input type="text" class="form-control" name="prop_case_num" id="prop_case_num" value="<?php $prop_case_num =time().mt_rand (10,99); echo $prop_case_num; ?>" required="required" autofocus>'+
        '</div>'+
        '<div class = "form-group col-lg-6">  '+ '<label for="invoice_no">Invoice Number</label><input type="text" class="form-control" name="invoice_no" id="invoice_no" value="<?php $wo_num =mt_rand (10,99).time(); echo $wo_num; ?>" required="required" autofocus>'+'</div>'+
        ' </div>  '+      

      '  <div class = "row">      '+
    
    '<div class = "form-group col-lg-6">'+
    '  <div class="row">'+
' <div class="form-group col-lg-6">'+
'<label for="prop_zip">Zipcode</label>'+
'   <input type="text" class="form-control" maxlength="5" minlength="5" name="prop_zip" id="prop_zip" required="required">  '+                    

                '   </div>'+
    '    <div class="form-group col-lg-6">'+
    '          <label for="prop_city">City</label>'+
               

                   '    <input type="text" class="form-control" name="prop_city" id="prop_city" required="required">   '+ 

                 '  </div>'+
                
                  
               
                     ' </div>'+

             '  <div class="row">'+ '   <div class="form-group col-lg-6">'+
                 '  <label for="prop_county">County</label>'+
               

                     '  <input type="text" class="form-control" name="prop_county" id="prop_county">  '+
                   
                     '</div>'+

                  ' <div class="form-group col-lg-6">'+
                  '  <label for="prop_state">State</label>'+

                 '  <select class="form-control" name="prop_state"  id="prop_state" required="required">'+
                 ' <option value="" disabled="disabled" selected="selected">Select State</option>'+

'<option value="AL">Alabama</option>'+
'<option value="AK">Alaska</option>'+
'<option value="AZ">Arizona</option>'+
'<option value="AR">Arkansas</option>'+
'<option value="CA">California</option>'+
'<option value="CO">Colorado</option>'+
'<option value="CT">Connecticut</option>'+
'<option value="DE">Delaware</option>'+
'<option value="DC">District of Columbia</option>'+
'<option value="FL">Florida</option>'+
'<option value="GA">Georgia</option>'+
'<option value="HI">Hawaii</option>'+
'<option value="ID">Idaho</option>'+
'<option value="IL">Illinois</option>'+
'<option value="IN">Indiana</option>'+
'<option value="IA">Iowa</option>'+
'<option value="KS">Kansas</option>'+
'<option value="KY">Kentucky</option>'+
'<option value="LA">Louisiana</option>'+
'<option value="ME">Maine</option>'+
'<option value="MD">Maryland</option>'+
'<option value="MA">Massachusetts</option>'+
'<option value="MI">Michigan</option>'+
'<option value="MN">Minnesota</option>'+
'<option value="MS">Mississippi</option>'+
'<option value="MO">Missouri</option>'+
'<option value="MT">Montana</option>'+
'<option value="NE">Nebraska</option>'+
'<option value="NV">Nevada</option>'+
'<option value="NH">New Hampshire</option>'+
'<option value="NJ">New Jersey</option>'+
'<option value="NM">New Mexico</option>'+
'<option value="NY">New York</option>'+
'<option value="NC">North Carolina</option>'+
'<option value="ND">North Dakota</option>'+
'<option value="OH">Ohio</option>'+
'<option value="OK">Oklahoma</option>'+
'<option value="OR">Oregon</option>'+
'<option value="PA">Pennsylvania</option>'+
'<option value="RI">Rhode Island</option>'+
'<option value="SC">South Carolina</option>'+
'<option value="SD">South Dakota</option>'+
'<option value="TN">Tennessee</option>'+
'<option value="TX">Texas</option>'+
'<option value="UT">Utah</option>'+
'<option value="VT">Vermont</option>'+
'<option value="VA">Virginia</option>'+
'<option value="WA">Washington</option>'+
'<option value="WV">West Virginia</option>'+
'<option value="WI">Wisconsin</option>'+
'<option value="WY">Wyoming</option>'+
'</select>'+
'</div>'+

              ' </div>'+
           
           
              ' </div>    '+  
 ' <div class = "form-group col-lg-6">'+

    '   </div>   '+ ' </div>'+' <div class = "row">'+  
 ' <div class = "form-group col-lg-6">'+
 '     <label for="prop_full_add">Address</label> '+         
 '     <textarea rows="4" name="prop_full_add" class = "form-control" id="prop_full_add" placeholder=""  maxlength="5000"></textarea>  '+

    '   </div>   '+  
 ' <div class = "form-group col-lg-6">'+

    '   </div>   '+' </div>'; 


      $("#new_invoice_if_add").html(data2); 

      $("#prop_zip").keyup(function() {
    if($(this).val().length == 5) {
        $("#prop_zip").prop('disabled', true);
        $("#prop_city").prop('disabled', true);
        $("#prop_county").prop('disabled', true);
        $("#prop_state").prop('disabled', true);

        var n = $(this).val(); 
        $.ajax({
        type: "POST",
        url: "prop_zip_search_adata.php",
        data:'data='+n,
        success: function(data){
            data = data.trim(); 
            if(data == 'no'){
                $("#prop_zip").prop('disabled', false);
                $("#prop_city").prop('disabled', false);
                $("#prop_county").prop('disabled', false);
                $("#prop_state").prop('disabled', false);
                $('#prop_zip').trigger("reset");                
                $('#prop_city').trigger("reset");                
                $('#prop_county').trigger("reset");
                $('#prop_state').trigger("reset");                

            }else{                
                var data_response = JSON.parse(data);

                var state = data_response.state;
                var state_id = data_response.s_id;
                var city = data_response.city;
                var country = data_response.country;
                var status_res = data_response.status; 
                var county = data_response.county;

                if(status_res = 'yes'){
                    $("#prop_zip").prop('disabled', false);

                    if(city.length >1){
                        $('input[name="prop_city"]').val(city);
                        $("#prop_city").prop('disabled', false);

                    }else{
                        $('input[name="prop_city"]').val(state);
                        $("#prop_city").prop('disabled', false);
                        $('#prop_city').trigger("reset"); 
                    }

                    if(county.length >1){
                        $('input[name="prop_county"]').val(county);
                        $("#prop_county").prop('disabled', false);

                    }else{
                        $('input[name="prop_county"]').val(county);
                        $("#prop_county").prop('disabled', false);
                        $('#prop_county').trigger("reset"); 
                    }

                    if(state_id.length >1){
                        $("#prop_state").val(state_id);
                        $("#prop_state").prop('disabled', false);
                    }else{
                        $("#prop_state").prop('disabled', false);
                        $('#prop_state').trigger("reset"); 
                    }
                   

                }else{
                    $("#prop_zip").prop('disabled', false);
                    $("#prop_city").prop('disabled', false);
                    $("#prop_county").prop('disabled', false);
                    $("#prop_state").prop('disabled', false);
                    $('#prop_zip').trigger("reset");                
                    $('#prop_city').trigger("reset");                
                    $('#prop_county').trigger("reset");
                    $('#prop_state').trigger("reset");   
                }

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






<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.3.min.js"></script>

    
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/dataTables.bootstrap.min.js"></script>
<script src="js/dataTables.responsive.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script> 
<script src="js/jquery_acomplete.min.js"></script>


<script>
 var countries = [<?php
            $query_fetch_client = "SELECT * FROM client WHERE client_is_delete IS NULL AND is_approve = 1";
            $run_fetch_client = mysqli_query($conn, $query_fetch_client);
            if(mysqli_num_rows($run_fetch_client)>0){
                while($row_fetch_client = mysqli_fetch_array($run_fetch_client)){
                    $client_id = $row_fetch_client['client_id'];
                    $client_alias = $row_fetch_client['client_alias'];
                    $client_name = $row_fetch_client['client_name'];
            ?>{ value: '<?php echo $client_alias." - " .$client_name;?>', data: '<?php echo $client_id;?>' },<?php
            }}
            ?>];

$('#new_invoice_client_name1').autocomplete({
    lookup: countries,
    onSelect:function (suggestion){
    var val1 = suggestion.data;

  document.getElementById("new_invoice_client_name").value = val1;
  if(typeof(val1) != 'undefined' || val1 != null){ 
    var elemxxxq = document.querySelector('#new_invoice_wo');
        
        elemxxxq.style.display = 'none';
      
    var data33 = '';
         $("#new_invoice_if_add").html(data33);   
        $.ajax({
        type: "POST",
        url: "get_new_invoice_client_prop.php",
        data:'cl_id='+val1,
        success: function(data){
            $("#new_invoice_prop_column").html(data);
        }
        });
    }  
}
});
 </script> 
  <?php include_once "search_footer.php" ?>
</body>

</html>
