<?php
include "include/db.php";
include "include/auth.php";

if(isset($_REQUEST['in_no'])){
    if(strlen($_REQUEST['in_no']) >0){
        $invoice_id = $_REQUEST['in_no'];
        $query_check_wo = "SELECT * FROM invoice WHERE invoice_id = $invoice_id AND is_delete IS NULL";
        $run_check_wo = mysqli_query($conn, $query_check_wo);

        if(mysqli_num_rows($run_check_wo) ==1){
            while($row_check_wo = mysqli_fetch_array($run_check_wo)){
                $invoice_no = $row_check_wo['invoice_no'];
                $client_id = $row_check_wo['client_id'];
                $prop_id = $row_check_wo['prop_id'];
                $invoice_type = $row_check_wo['invoice_type'];
                $invoice_amount_table = $row_check_wo['invoice_amount'];
                $invoice_create_time = $row_check_wo['create_time'];

                $current_timestamp = time();

                $invoice_due_timestamp = strtotime ('30 days', strtotime($invoice_create_time)) ;
                $show_client_pay = '';
                if($current_timestamp > $invoice_due_timestamp){
                    $show_client_pay = 'yes';
                }
                
                $is_system_bid1 = $row_check_wo['is_system_bid'];

                if($is_system_bid1 == NULL){
                    $is_system_bid = 'n';
                }
                if($is_system_bid1 == 1){
                    $is_system_bid = 'y';
                }
                
                if($is_system_bid1 == 0){
                    $is_system_bid = 'n';
                }
                
              
                $bid_wo_no = $row_check_wo['bid_wo_no'];

                if($bid_wo_no == NULL){
                    $bid_wo_no = '';
                }

                if(strlen($bid_wo_no) == 0){
                    $is_system_bid = 'n';
                }
                

                $bid_amount = $row_check_wo['bid_amount'];
                
                if($bid_amount == NULL){
                    $bid_amount = '';
                }

                if(strlen($bid_amount) == 0){
                    $is_system_bid = 'n';
                }

                $no_bid_reason = $row_check_wo['no_bid_reason'];
                
                if($no_bid_reason == NULL){
                    $no_bid_reason = '';
                }

                if(strlen($no_bid_reason) > 0){
                    $is_system_bid = 'n';
                }
                
                $invoice_client_pay = $row_check_wo['client_pay'];
                if($invoice_client_pay == NULL){
                    $invoice_client_pay = 0;
                }
                $projected_profit_color = '';
                $invoice_vendor_pay = $row_check_wo['vendor_pay'];
                $is_vendor_comment_box = 'false';

                if($invoice_vendor_pay == NULL){
                    $invoice_vendor_pay = '';
                }            
               

                $is_vendor_comment = $row_check_wo['is_vendor_comment'];
                $no_vendor_comment = '';
                $no_vendor_comment = $row_check_wo['vendor_comment'];
                $comment_string_set = 'false';
                
                if(strlen($no_vendor_comment) > 0){
                    $comment_string_set = 'true';
                }
               

                
                if(isset($is_vendor_comment)){
                    if($is_vendor_comment == 1 && $comment_string_set == 'true'){
                        $is_vendor_comment_box = 'true';
                    }
                    if($is_vendor_comment == 2){
                        $is_vendor_comment_box = 'true';
                    }
                }

                if($invoice_amount_table > 0 && $invoice_vendor_pay >0){
                    $invoice_projected_profit = $invoice_amount_table - $invoice_vendor_pay;
                    $invoice_projected_profit = number_format($invoice_projected_profit, 2, '.', '');

                    $pro_profit_per_cent = $invoice_projected_profit/$invoice_amount_table;
                    $pro_profit_per_cent = $pro_profit_per_cent * 100;
                    if($pro_profit_per_cent > 39.9){
                        $projected_profit_color = "border-color:green; border-width:3px;";
                    }elseif($pro_profit_per_cent > 25 && $pro_profit_per_cent < 40){
                        $projected_profit_color = "border-color:yellow; border-width:3px;";
                    }elseif($pro_profit_per_cent < 25){
                        $projected_profit_color = "border-color:red; border-width:3px;";
                    }

                }else{
                    $invoice_projected_profit = '-';
                }
                $actual_profit_color = '';
                if($invoice_client_pay > 0 && $invoice_vendor_pay >0){
                    $invoice_actual_profit = $invoice_client_pay - $invoice_vendor_pay;
                    $invoice_actual_profit = number_format($invoice_actual_profit, 2, '.', '');
                    $act_profit_per_cent = $invoice_actual_profit/$invoice_client_pay;
                    $act_profit_per_cent = $act_profit_per_cent * 100;
                    if($act_profit_per_cent > 39.9){
                        $actual_profit_color = "border-color:green; border-width:3px;";
                    }elseif($act_profit_per_cent > 25 && $act_profit_per_cent < 40){
                        $actual_profit_color = "border-color:yellow; border-width:3px;";
                    }elseif($act_profit_per_cent < 25){
                        $actual_profit_color = "border-color:red; border-width:3px;";
                    }
                }else{
                    $invoice_actual_profit = '-';
                }
                
                $query_client_detail = "SELECT * FROM client WHERE client_id = $client_id";
                $run_client_detail = mysqli_query($conn, $query_client_detail);

                if(mysqli_num_rows($run_client_detail) ==1){
                    while($row_client_detail = mysqli_fetch_array($run_client_detail)){
                        $client_alias = $row_client_detail['client_alias'];
                       
                    }
                }

            }            
        }else{
            header("Location:index.php");  
        }
    }else{
        header("Location:index.php");    
    }
}else{
    header("Location:index.php");
}


$query_check_wo123 = "SELECT * FROM invoice WHERE invoice_id = $invoice_id AND is_delete IS NULL";
        $run_check_wo123 = mysqli_query($conn, $query_check_wo123);

        if(mysqli_num_rows($run_check_wo123) ==1){
while($row_check_wo123 = mysqli_fetch_array($run_check_wo123)){
      
    $invoice_type = $row_check_wo123['invoice_type'];
}
        }



include "header.php";
?>
<style>
.parent {
  display: flex;
}

.child {
  flex: 1;
}
.childq{
    padding-left: 15px;
    padding-right:15px;
}
</style>
<style>
body {
  padding-top: 50px;
}

/*modal fullscreen */

.modal.modal-fullscreen {
  /* Maximize the main wrappers on the screen */
  /* Make the parent wrapper of the modal box a full-width block */
  /* Remove borders and effects on the content */
  /**
	 * /!\ By using this feature, you force the header and footer to be placed
	 * in an absolute position. You must handle by yourself the margin of the
	 * content.
	 */
}
.modal.modal-fullscreen .modal-dialog,
.modal.modal-fullscreen .modal-content {
  bottom: 0;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
}
.modal.modal-fullscreen .modal-dialog {
  margin: 0;
  width: 100%;
  animation-duration:0.6s;
}
.modal.modal-fullscreen .modal-content {
  border: none;
  -moz-border-radius: 0;
  border-radius: 0;
  -webkit-box-shadow: inherit;
  -moz-box-shadow: inherit;
  -o-box-shadow: inherit;
  box-shadow: inherit;
  /* change bg color below */
 /* background:#1abc9c; */
}
.modal.modal-fullscreen.force-fullscreen {
  /* Remove the padding inside the body */
}
.modal.modal-fullscreen.force-fullscreen .modal-body {
  padding: 0;
}
.modal.modal-fullscreen.force-fullscreen .modal-header,
.modal.modal-fullscreen.force-fullscreen .modal-footer {
  position: relative;
  bottom: 0;
}
.modal.modal-fullscreen.force-fullscreen .modal-header {
  top: 0;
}

/* The styles above for the modal-body, footer, etc aren't being applied so I tried the ones below and they work */
.modal-body {
  height: 100%;
}

.modal-footer {
  width: 100%;
  position: relative;
  bottom: 0;
  background-color: #FFF;
}

.parent-i {
  display: flex;
  flex-direction: row;
  width: 100%;
}
.parent-i .child-i {
  margin: .5em;
}
.parent-i .child-i:first-of-type {
  margin-left: 1em;
}
.parent-i .child-i:last-of-type {
  margin-right: 1em;
}

</style>
<div id="page-wrapper">
<h3 style = "color:#0b57a4; font-weight:bolder;padding-bottom:0;margin-bottom:0;text-align:center">INVOICE</h3> 
<div class="modal fade modal-fullscreen  footer-to-bottom" id="myModalFullscreen<?php echo $invoice_id;?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog animated zoomInLeft">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">Close</button>
                	<h4 class="modal-title">Invoice Preview</h4>
            </div>
            <div class="modal-body">
             <iframe src="invoice-maker.php?in_no=<?php echo $invoice_id;?>&state=view" style="width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:10;" id = "iframe-modal">
    Your browser doesn't support iframes
</iframe>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
               
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal --><br>
<a class='btn btn-default' style = "color:#337ab7;font-weight:bold;" href='add-items-invoice.php?state=<?php echo $invoice_type;?>&in_no=<?php echo $invoice_id;?>&client_id=<?php echo $client_id;?>&invoice_no=<?php echo $invoice_no;?>' id = ''><i class="fa fa-plus fa-fw"></i>Add more items</a>&nbsp&nbsp<?php if($invoice_type == 2){?><a class='btn btn-success' href='invoice-maker.php?in_no=<?php echo $invoice_id;?>&state=download' id = ''>Download</a>&nbsp&nbsp<a class="btn btn-primary" data-toggle="modal" data-target="#myModalFullscreen<?php echo $invoice_id; ?>" contenteditable="false">Preview</a>&nbsp&nbsp<?php }?><a class='btn btn-warning' href='index.php' id = ''>Exit</a><br>
<h3>Customize Details For Invoice# - <?php echo $invoice_no; ?> for <?php echo $client_alias; ?></h3>
<div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
            <div class="panel-body">
<!-- id="dataTables-bidwizqwe2" --> 
                            <table width="100%" class="table table-striped table-bordered table-hover">
                                    <thead style = "color:#ffffff; background-color:#337ab7;border-color:#337ab7">
                                        <tr>
                                                <th style = "min-width:350px;">
                                                    MAPS Name
                                                </th>
                                                <th>
                                                   Actual Image
                                                </th>       
                                                <th>
                                                   Quantity
                                                </th> 
                                                <th>
                                            Unit Price                                           </th>
                                                
                                                <th>
                                               Total
                                                </th>
                                               
                                            </tr>
                                        </thead>
                                        <tbody>
<?php
$query_bid_item = "SELECT * FROM invoice_item WHERE invoice_id = $invoice_id AND is_delete IS NULL";
$run_bid_item = mysqli_query($conn, $query_bid_item);
if(mysqli_num_rows($run_bid_item) >0){
    while($row_bid_item = mysqli_fetch_array($run_bid_item)){
        $invoice_item_id = $row_bid_item['invoice_item_id'];
        $maps_id = $row_bid_item['maps_id'];
        $invoice_item_amount = $row_bid_item['invoice_item_amount'];
        $invoice_item_quantity = $row_bid_item['invoice_item_quantity'];
        $invoice_item_total = $row_bid_item['invoice_item_total'];
        $maps_desc = $row_bid_item['invoice_item_desc'];
        $invoice_item_uom = $row_bid_item['invoice_item_uom'];   
        $bid_item_image = "SELECT * FROM invoice_actual_image WHERE item_id = $invoice_item_id ORDER BY image_id ASC";
        $bid_item_image_run = mysqli_query($conn, $bid_item_image);
        $cnt_id = mysqli_num_rows($bid_item_image_run);
        
        if($cnt_id > 29){
            $hide_submit = "display:none;";
        }else{
            $hide_submit = "";
        }
        $query_maps = "SELECT * FROM maps WHERE maps_id = $maps_id";
        $run_maps = mysqli_query($conn, $query_maps);
        $row_maps = mysqli_fetch_array($run_maps);
        $maps_name = $row_maps['maps_name'];
        $maps_name = strtoupper($maps_name);
        if ($maps_desc == NULL){            
            $maps_desc = $row_maps['maps_desc'];
        }
       

        if($invoice_item_amount == NULL){
            $invoice_item_amount = 0;   
        }
       
        if($invoice_item_quantity == NULL){
            $invoice_item_quantity = 1;   
        }

        $invoice_item_amount = number_format($invoice_item_amount, 2, '.', '');


        $invoice_item_total = number_format($invoice_item_total, 2);
        if($invoice_item_total == 0.00 || $invoice_item_total == NULL){
            $invoice_item_total = 0; 
        }
        if($invoice_item_uom != 2 && $invoice_item_uom != 4 && $invoice_item_uom != 1  && $invoice_item_uom != 5 && $invoice_item_uom != 6 && $invoice_item_uom != 7 && $invoice_item_uom != 8){
            $invoice_item_uom = 0;
        }
        
        $arr = array('maps' => $maps_id, 'cl_id' => $client_id, 'in_no' => $invoice_id, 'invoice_no' => $invoice_no, 'state' => $invoice_type);
        $rem_json = json_encode($arr);
        if($invoice_item_uom == 2){
            $uom_data_2 = 'set';
            if($invoice_item_total > $invoice_item_amount){
                $uom_data_2_display = "set";
            }else{
                $uom_data_2_display = "";
            }
        }else{
            $uom_data_2 = "";
        }
        
    echo '<tr class="odd gradeX" id = "rowQ-'.$maps_id.'"  style = "min-height:350px;">';    

    echo '<td'. ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':'').'>';   

    echo $maps_name.'<br>
    
    <span id = "editItemSpan-'.$maps_id.'" style = "font-style: oblique">' .$maps_desc. '</span>
    
    <span id = "editItemDisplay-'.$maps_id.'"><button type="button" onclick="editItemN('.$maps_id.')" class="btn btn-default" style = "float: right"><i class="fa fa-edit fa-fw"></i></button><br> <br>';
    echo '<button type="button" onclick="remItemRN('.$invoice_item_id.')" class="btn btn-danger" style = "">Remove</button></span>';
    
    echo '<span id = "editItemForm-'.$maps_id.'" style = "display:none"><input style = "width:80%" class="form-control" id = "inputItemForm'.$maps_id.'" type = "text" value = "'.$maps_desc.'"><button type="button" id = "descEditsub'.$maps_id.'" onclick="updateItemN('.$maps_id.')" class="btn btn-default" style = "float: right"><i class="fa fa-check fa-fw"></i></button>';

    echo "<input type = 'hidden' id = 'remJSON-$invoice_item_id' value='$rem_json'></span>";

    echo '</td>';
       ?>
<td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>>  
    <div id="err<?php echo $invoice_item_id; ?>" class = "alert alert-danger" style = "display:none">       
    </div>

    <div id="uploading_i<?php echo $invoice_item_id; ?>" class = "alert alert-info" style = "display:none">
        <p>Loading..</p>
    </div>  

<?php
    $bid_item_image = "SELECT * FROM invoice_actual_image WHERE item_id = $invoice_item_id";
    $bid_item_image_run = mysqli_query($conn, $bid_item_image);

    $no_images = mysqli_num_rows($bid_item_image_run);
    $image_ac = 1;
    $bid_item_image_arr["set"] = "";
    while($bid_item_image_row = mysqli_fetch_array($bid_item_image_run)){
        $act_image_path = $bid_item_image_row['image_name'];
        $bid_item_image_arr["$image_ac"] = "$act_image_path";

        $image_ac++;    
    }
    

    for($image_number = 1; $image_number < 31; $image_number++){
        if(isset($bid_item_image_arr["$image_number"])){
            $path_u = $bid_item_image_arr["$image_number"];
        }else{
            $path_u = "";
        }   
        

        if(strlen($path_u) > 0){
            $path = "maps_act_image.php?i=".$path_u;
        }else{
            $path = "";
        }

        if(strlen($path) == 0){
            $is_remove = "display:none;";
        }else{
            $is_remove = "";
        }

if($image_number == 1){        

?>

<div class="parent-i">

<?php }?>
<div id="ipreview<?php echo $image_number; ?>-<?php echo $invoice_item_id; ?>" class = "child-i" style = "<?php echo $is_remove; ?>"> 
    <div id="preview<?php echo $image_number; ?>-<?php echo $invoice_item_id; ?>">
        <img src="<?php echo $path; ?>" style="max-height:50px; max-width:150px" />
    </div>
    <button type = "button" class="btn btn-danger" id="remove_i<?php echo $image_number; ?>-<?php echo $invoice_item_id; ?>" style = "margin-bottom:4px;margin-top:4px;<?php echo $is_remove; ?>" onclick="remPicWO('<?php echo $image_number; ?>-<?php echo $invoice_item_id; ?>')" >Remove</button>            
</div>
<?php 
$remainder = $image_number % 4;
if($remainder == 0){
?>
</div>
<div class="parent-i">
<?php } 
if($image_number == 30){
    echo "</div>";
}
?>  
<?php  } 
    unset($bid_item_image_arr);
?>  
<div id="uploadImagex<?php echo $invoice_item_id; ?>" style = "<?php echo $hide_submit; ?>">
        
    <form class="form-image">
        <input id="uploadImage<?php echo $invoice_item_id; ?>" type="file" accept="image/*" name="uploadImage[]" style = "padding-top:15px;" multiple required>
        <input name = "invoice_item_i" type = "hidden" value = "<?php echo $invoice_item_id; ?>">
        <input name = "rem_count" type = "hidden" value = "<?php echo $cnt_id; ?>">
        <input class="btn btn-default" type="submit" value="Upload" style = "margin-top:5px">
    </form>
</div>    
</td>
       <?php
        if($invoice_item_uom == 0){     

?>
            <td><div class='parent'>
            <button type="button" onclick="remQtyIN(<?php echo $maps_id; ?>)" class="btn btn-danger child"><i class="fa fa-minus fa-fw"></i></button>
            
            <span id = "cellQ-<?php echo $maps_id; ?>" class = "child childq"><?php echo $invoice_item_quantity; ?></span>
            
            <button type="button" onclick="addQtyIN(<?php echo $maps_id; ?>)" class="btn btn-success child"><i class="fa fa-plus fa-fw"></i></button></div></td>
            
            <?php
            }elseif($invoice_item_uom == 1  || $invoice_item_uom == 5  || $invoice_item_uom == 6  || $invoice_item_uom == 7  || $invoice_item_uom == 8){               
                    $query = "SELECT * FROM uom_field WHERE uom_id = $invoice_item_uom AND uom_field_type = 'bidin'";
                      $run = mysqli_query($conn, $query);
                    ?>
                    <td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>>
                    <?php
                        $cont_field_value = 0;
                        foreach($run as $uom_field) {
                    ?>
                    <div class = 'form-group'>
                    <label for="<?php echo $uom_field['uom_field_name']?>"><?php echo $uom_field['uom_field_title']?></label>
                    <?php 
                    
                     $uom_field_id = $uom_field['uom_field_id'];
                    if(empty($uom_field_id)){
                        $uom_field_value = '';
                    }else{
                        $query1 = "SELECT * FROM invoice_item_uom_value WHERE invoice_item_id = $invoice_item_id AND invoice_item_uom_field_id = $uom_field_id";
                        $run1 = mysqli_query($conn, $query1);
                        $num_uom_value = mysqli_num_rows($run1);
                        $row = mysqli_fetch_array($run1);
                        $uom_field_value = $row['invoice_item_uom_value_amount'];
                        if($uom_field_value == NULL){
                            $cont_field_value ++;
                        }
                        if($num_uom_value == 0){
                            $uom_field_value = '';
                        }
                    
                    }?>
                      <input type='text' class='form-control' name='<?php echo $uom_field['uom_field_name']?>' id='<?php echo $uom_field['uom_field_name']?>-<?php echo $invoice_item_id; ?>' value='<?php echo $uom_field_value; ?>' <?php if(strlen($uom_field_value) > 0){echo 'disabled';} ?> >
                      </div>
                    <?php
                      }
                    ?>
                    
                     <button type="button" onclick="setUoMval('<?php echo $invoice_item_id; ?>-<?php echo $invoice_item_uom; ?>')" class="btn btn-default" id='uomCalc-<?php echo $invoice_item_id; ?>' <?php if($cont_field_value == 0){echo 'style = "display:none"';} ?>>
                        Calculate
                    </button>
                   

                    <?php
    if($invoice_item_uom == 5  || $invoice_item_uom == 8){
    ?>
    
    <button type="button" onclick="unsetUoMval1(<?php echo $invoice_item_id; ?>)" class="btn btn-warning" id='uomEdit-<?php echo $invoice_item_id; ?>' <?php if($num_uom_value == 0 || $cont_field_value > 0){echo 'style = "display:none"';} ?>>
    <i class="fa fa-edit fa-fw"></i>
</button>

    <?php
    }elseif($invoice_item_uom == 7){
     
    ?>
<button type="button" onclick="unsetUoMval3(<?php echo $invoice_item_id; ?>)" class="btn btn-warning" id='uomEdit-<?php echo $invoice_item_id; ?>' <?php if($num_uom_value == 0 || $cont_field_value > 0){echo 'style = "display:none"';} ?>>
    <i class="fa fa-edit fa-fw"></i>
</button>

<?php
    }else{
     
    ?>
<button type="button" onclick="unsetUoMval(<?php echo $invoice_item_id; ?>)" class="btn btn-warning" id='uomEdit-<?php echo $invoice_item_id; ?>' <?php if($num_uom_value == 0 || $cont_field_value > 0){echo 'style = "display:none"';} ?>>
    <i class="fa fa-edit fa-fw"></i>
</button>



<?php
    }
     
    ?>
                    
                    </td>
                    
                    
                    <?php    }elseif($invoice_item_uom == 2){ 
            $query22 = "SELECT * FROM uom_field WHERE uom_id = $invoice_item_uom AND uom_field_type = 'maps' AND uom_field_name = 'maps_uom_val3'";
            $run22 = mysqli_query($conn, $query22);

            if(mysqli_num_rows($run22) > 0){
                $row22 = mysqli_fetch_array($run22);
                $invoice_uom2_maps_uom_val3 = $row22['uom_field_id'];
            }

           
            $query222 = "SELECT * FROM maps_uom_value WHERE maps_id = $maps_id AND uom_field_id = $invoice_uom2_maps_uom_val3";
            $run222 = mysqli_query($conn, $query222);

            if(mysqli_num_rows($run222) > 0){
                $row222 = mysqli_fetch_array($run222);
                $maps_uom_value_amount3 = $row222['maps_uom_value_amount'];
                if($maps_uom_value_amount3 > 0){
                    $uom_data_2_eq = 'set';
                }else{
                    $uom_data_2_eq = '';
                }

                $maps_uom_value_amount3 = number_format($maps_uom_value_amount3, 2, '.', '');
            }

            $query33 = "SELECT * FROM uom_field WHERE uom_id = $invoice_item_uom AND uom_field_type = 'maps' AND uom_field_name = 'maps_uom_val4'";
            $run33 = mysqli_query($conn, $query33);

            if(mysqli_num_rows($run33) > 0){
                $row33 = mysqli_fetch_array($run33);
                $invoice_uom2_maps_uom_val4 = $row33['uom_field_id'];
            }

           
            $query333 = "SELECT * FROM maps_uom_value WHERE maps_id = $maps_id AND uom_field_id = $invoice_uom2_maps_uom_val4";
            $run333 = mysqli_query($conn, $query333);

            if(mysqli_num_rows($run333) > 0){
                $row333 = mysqli_fetch_array($run333);
                $maps_uom_value_amount4 = $row333['maps_uom_value_amount'];
                if($maps_uom_value_amount4 > 0){
                    $uom_data_2_cut = 'set';
                }else{
                    $uom_data_2_cut = '';
                }
                $maps_uom_value_amount4 = number_format($maps_uom_value_amount4, 2, '.', '');
            }

$query = "SELECT * FROM uom_field WHERE uom_id = $invoice_item_uom AND uom_field_type = 'bidin'";
  $run = mysqli_query($conn, $query);
?>
<td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>>
<?php
    $cont_field_value = 0;
    foreach($run as $uom_field) {
?>
<div class = 'form-group'>
<label for="<?php echo $uom_field['uom_field_name']?>"><?php echo $uom_field['uom_field_title']?></label>
<?php 

 $uom_field_id = $uom_field['uom_field_id'];
if(empty($uom_field_id)){
    $uom_field_value = '';
}else{
    $query1 = "SELECT * FROM invoice_item_uom_value WHERE invoice_item_id = $invoice_item_id AND invoice_item_uom_field_id = $uom_field_id";
    $run1 = mysqli_query($conn, $query1);
    $num_uom_value = mysqli_num_rows($run1);
    $row = mysqli_fetch_array($run1);
    $uom_field_value = $row['invoice_item_uom_value_amount'];
    if($uom_field_value == NULL){
        $cont_field_value ++;
    }
    if($num_uom_value == 0){
        $uom_field_value = '';
    }

}?>
  <input type='text' class='form-control' name='<?php echo $uom_field['uom_field_name']?>' id='<?php echo $uom_field['uom_field_name']?>-<?php echo $invoice_item_id; ?>' value='<?php echo $uom_field_value; ?>' <?php if(strlen($uom_field_value) > 0){echo 'disabled';} ?> >
  </div>
<?php
  }
?>

 <button type="button" onclick="setUoMval('<?php echo $invoice_item_id; ?>-<?php echo $invoice_item_uom; ?>')" class="btn btn-default" id='uomCalc-<?php echo $invoice_item_id; ?>' <?php if($cont_field_value == 0){echo 'style = "display:none"';} ?>>
    Calculate
</button>

 <button type="button" onclick="unsetUoMval(<?php echo $invoice_item_id; ?>)" class="btn btn-warning" id='uomEdit-<?php echo $invoice_item_id; ?>' <?php if($num_uom_value == 0 || $cont_field_value > 0){echo 'style = "display:none"';} ?>>
    <i class="fa fa-edit fa-fw"></i>
</button>

</td>


<?php    }elseif($invoice_item_uom == 4){ 

$query = "SELECT * FROM uom_field WHERE uom_id = $invoice_item_uom AND uom_field_type = 'bidin'";
  $run = mysqli_query($conn, $query);
?>
<td>
<?php
    $cont_field_value = 0;
    foreach($run as $uom_field) {
?>

<?php 

 $uom_field_id = $uom_field['uom_field_id'];
if(empty($uom_field_id)){
    $uom_field_value = '';
}else{
    $query1 = "SELECT * FROM invoice_item_uom_value WHERE invoice_item_id = $invoice_item_id AND invoice_item_uom_field_id = $uom_field_id";
    $run1 = mysqli_query($conn, $query1);
    $num_uom_value = mysqli_num_rows($run1);
    $row = mysqli_fetch_array($run1);
    $uom_field_value = $row['invoice_item_uom_value_amount'];
    if($uom_field_value == NULL){
        $cont_field_value ++;
    }
    if($num_uom_value == 0){
        $uom_field_value = '';
    }

}

if($uom_field['uom_field_name'] == 'bidin_uom_val1'){

?>
<div class="form-group">
<label for="<?php echo $uom_field['uom_field_name']?>"><?php echo $uom_field['uom_field_title']?></label>
  <input type='text' class='form-control' name='<?php echo $uom_field['uom_field_name']?>' id='<?php echo $uom_field['uom_field_name']?>-<?php echo $invoice_item_id; ?>' value='<?php echo $uom_field_value; ?>' <?php if(strlen($uom_field_value) > 0){echo 'disabled';} ?> >
  </div>

<?php
}elseif($uom_field['uom_field_name'] == 'bidin_uom_val2'){ ?>
<div class="form-group">
    <label for="<?php echo $uom_field['uom_field_name']?>"><?php echo $uom_field['uom_field_title']?></label>

    <select name="<?php echo $uom_field['uom_field_name']?>" class='form-control' id="<?php echo $uom_field['uom_field_name']?>-<?php echo $invoice_item_id; ?>" required <?php if(strlen($uom_field_value) > 0){echo 'disabled';} ?>>
    <?php if($uom_field_value == '1'){ ?>
        <option value='1' selected="selected">Normal Hours (6am-5pm)</option>
        <option value='2'>Emergency After Hours (5pm-6am)</option>
    <?php }elseif($uom_field_value == '2'){ ?>
        <option value='2' selected="selected">Emergency After Hours (5pm-6am)</option>
        <option value='1'>Normal Hours (6am-5pm)</option>
        <?php }else{ ?>
            <option value='1' selected="selected">Normal Hours (6am-5pm)</option>
        <option value='2'>Emergency After Hours (5pm-6am)</option>

        <?php } ?>

     </select>
    </div>
    <?php
    }elseif($uom_field['uom_field_name'] == 'bidin_uom_val3'){?>

        <div class="form-group">
    <label for="<?php echo $uom_field['uom_field_name']?>"><?php echo $uom_field['uom_field_title']?></label>

    <select name="<?php echo $uom_field['uom_field_name']?>" class='form-control' id="<?php echo $uom_field['uom_field_name']?>-<?php echo $invoice_item_id; ?>" required <?php if(strlen($uom_field_value) > 0){echo 'disabled';} ?>>    
    <option value='1'<?php if($uom_field_value == '1' || strlen($uom_field_value) == 0){ echo 'selected="selected"';} ?>>No Steep Pitch Upcharge</option>
    <option value='2' <?php if($uom_field_value == '2'){ echo 'selected="selected"';} ?>>8/12 Roof Pitch</option>
    <option value='3' <?php if($uom_field_value == '3'){ echo 'selected="selected"';} ?>>9/12 Roof Pitch</option>
    <option value='4' <?php if($uom_field_value == '4'){ echo 'selected="selected"';} ?>>10/12 Roof Pitch</option>
    <option value='5' <?php if($uom_field_value == '5'){ echo 'selected="selected"';} ?>>11/12 Roof Pitch</option>
    <option value='6' <?php if($uom_field_value == '6'){ echo 'selected="selected"';} ?>>12/12 Roof Pitch</option>
     </select>
    </div>
        
        <?php
        }elseif($uom_field['uom_field_name'] == 'bidin_uom_val4'){?>
<div class="form-group">
        <label for="<?php echo $uom_field['uom_field_name']?>"><?php echo $uom_field['uom_field_title']?></label>
    
        <select name="<?php echo $uom_field['uom_field_name']?>" class='form-control' id="<?php echo $uom_field['uom_field_name']?>-<?php echo $invoice_item_id; ?>" required <?php if(strlen($uom_field_value) > 0){echo 'disabled';} ?>>    
        <option value='1'<?php if($uom_field_value == '1' || strlen($uom_field_value) == 0){ echo 'selected="selected"';} ?>>No Multi-Storey Upcharge</option>
        <option value='2' <?php if($uom_field_value == '2'){ echo 'selected="selected"';} ?>>2 Storey Upcharge</option>
        <option value='3' <?php if($uom_field_value == '3'){ echo 'selected="selected"';} ?>>3 Storey Upcharge</option>
       
         </select>
        </div>
            
            <?php
            }
        ?>
   
 
    <?php
  }
?>
 <button type="button" onclick="setUoMval('<?php echo $invoice_item_id; ?>-<?php echo $invoice_item_uom; ?>')" class="btn btn-default" id='uomCalc-<?php echo $invoice_item_id; ?>' <?php if($cont_field_value == 0){echo 'style = "display:none"';} ?>>
    Calculate
</button>

 <button type="button" onclick="unsetUoMval4(<?php echo $invoice_item_id; ?>)" class="btn btn-warning" id='uomEdit-<?php echo $invoice_item_id; ?>' <?php if($num_uom_value == 0 || $cont_field_value > 0){echo 'style = "display:none"';} ?>>
    <i class="fa fa-edit fa-fw"></i>
</button>

</td>


<?php    }        

?>      

 <?php
        if($invoice_item_uom == 0){       

            echo '<td id = "editItemPForm-'.$maps_id.'" style = "display:none"><input style = "width:80%" id = "inputItemPForm'.$maps_id.'" type = "text" value = "'.$invoice_item_amount.'" class="form-control" ><button type="button" onclick="updateItemP('.$maps_id.')" class="btn btn-default" style = "float: right"><i class="fa fa-check fa-fw"></i></button></td>';
            
            echo '<td id = "editItemPDisplay-'.$maps_id.'"><span id = "editItemPSpan-'.$maps_id.'">' .$invoice_item_amount. '</span><button type="button" onclick="editItemP('.$maps_id.')" class="btn btn-default" style = "float: right"><i class="fa fa-edit fa-fw"></i></button></td>';

           
            }
        elseif($invoice_item_uom == 2){ ?>

<td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>>
   <span id = "uom2-gc-amount<?php echo $invoice_item_id;?>"><?php echo $invoice_item_amount;?></span>
</td>


<?php    }


        else{ ?>
<td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>> <span id = "totalI-<?php echo $maps_id; ?>">
<?php echo $invoice_item_amount;?></span></td>



<?php    }

?> 




<!--  -->           

<?php         
     echo '<td id = "totalQ-'.$maps_id.'"'.($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':'').'>' .$invoice_item_total. '</td>';
     echo '</tr>';    
     if($uom_data_2 == 'set'){?>
        <tr  class="odd gradeX"  <?php  if($uom_data_2_display == 'set' && $uom_data_2_eq == 'set'){echo "";}else{echo 'style = "display:none"';} ?> id = "row-uom2-eq<?php echo $invoice_item_id;?>"><!-- style = "display:none" -->
        <td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>>
           SPECIAL EQUIPMENT: 
           <br>
           <span  style = 'font-style: oblique'>Grass is over 3ft tall and will require additional special equipment in order to be cut.</span>
           </td><td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>></td><td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>></td><td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>><span id = "uom2-gc-eq-amount<?php echo $invoice_item_id;?>"><?php echo $maps_uom_value_amount3; ?></span></td><td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>></td></tr>
           <tr  class="odd gradeX" <?php  if($uom_data_2_display == 'set' && $uom_data_2_cut == 'set'){echo "";}else{echo 'style = "display:none"';} ?> id = "row-uom2-cut<?php echo $invoice_item_id;?>">
          <!--  -->
          <td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>>
        CLIPPINGS:
        <br>
        <span  style = 'font-style: oblique'>Pick up Grass remnant will need to be raked and bagged due to height of grass and excessive clippings.</span>
           </td><td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>></td><td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>></td><td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>><span id = "uom2-gc-cut-amount<?php echo $invoice_item_id;?>"><?php echo $maps_uom_value_amount4; ?></span></td><td <?php echo ($uom_data_2 == 'set'?' style="border-bottom:1px solid #f9f9f9;!important" ':''); ?>></td></tr>
           <tr  class="odd gradeX">
          
        <td>
        
           </td><td></td><td></td><td></td><td></td></tr>
           
          
       
            <?php 
           $uom_data_2 = 'unset'; 
           }     
        
    }
}
?>
</tbody>
<tfoot style = "color:#ffffff; background-color:#337ab7;border-color:#337ab7">
    <tr>
      <td>Invoice Amount</td>
      <td></td>
      <td></td>
     <td></td>   
    
      <td><span id = "bid_total_amount"><?php

       $invoice_amount_table = number_format($invoice_amount_table, 2);
      echo "$ ".$invoice_amount_table;      
      ?></span></td>
    </tr>
  </tfoot>
                                    
                                    </table>
        <form id="bid_submitted"> 
            <label for="is_bid_generated">Bid Created</label>
            <input type="radio" name="is_bid_generated" class="bid_created"<?php 
            if($is_system_bid == 'y'){ 
                echo ' checked '; 
            } 
            ?>value = "1" required id="" style = 'margin-left:55px;'>
            <label for="is_bid_generated">Yes</label>
            <input type="radio" name="is_bid_generated" class="bid_created"<?php 
            if($is_system_bid == 'n'){ 
                echo ' checked '; 
            } 
            ?>value = "0" required id="" style = 'margin-left:25px;'>
            <label for="is_bid_generated">No</label> 
        </form>      
           <div class="row">
                <div class="col-md-6"  id = 'bid_amount_message' style = 'display:none'>
                    <div class="alert alert-danger">
                        <strong><p id = 'bid_created_missing'></p></strong>
                    </div>
                </div>
                <div class="col-md-6">
                </div>
            </div>  
           <div class="row">  
           <div class="col-md-5">
           <div class="row" style = '<?php if(strlen($bid_wo_no) == 0){ echo 'display:none;'; } ?>' id = 'bid_details'>
           <div class="col-md-3">           
                <label for="">Bid #:</label>
            </div>
            <form id = 'bid_amount_form'>
                <div class="col-md-8">
                    <input type="text" name="bid_created_number" value="<?php if(strlen($bid_wo_no) > 0){ echo $bid_wo_no; } ?>" id="bid_created_number" required class="form-control" id="">                  
                </div>
                <div class="col-md-1">
                    <input type="submit" name="" required class="btn btn-success" id="">
                </div>
            </form>
        
            </div>
<br>
             <div class="row" style = '<?php if(strlen($bid_amount) == 0){ echo 'display:none;'; } ?>' id = 'bid_amount_details'>
           <div class="col-md-3">
           <label for="">Bid Amount:</label>
           </div>
           <div class="col-md-8">
            <input type="text" name="" disabled class="form-control" id="bid_created_amount" value = "<?php if(strlen($bid_amount) > 0){ echo $bid_amount; } ?>">
            </div>
            <div class="col-md-1">
            
            </div>
            
            </div>
<br>
            <div class="row"  style = '<?php if(strlen($bid_amount) > 0){ echo 'display:none;'; } ?>' id = 'bid_reason_details'>
           <div class="col-md-3">
           <label for="">Reason:</label>
           </div>
           <form id = 'bid_reason_form'>
           <div class="col-md-8">
          
            <textarea name="no_bid_reason" id="no_bid_reason" cols="30" rows="4" required class="form-control" placeholder='Enter reason for not making Bid'><?php if(strlen($no_bid_reason) > 0){ echo $no_bid_reason; } ?></textarea>
            </div>
            <div class="col-md-1">
            <input type="submit" name="" required class="btn btn-success" id="">
            </div>
            </form>
            </div>
            <br>
            <div class="row"  style = '<?php if($is_vendor_comment_box == 'false'){ echo 'display:none;';} ?>' id = 'vendor_comment'>
           <div class="col-md-3">
           <label for="">Comment:</label>
           </div>
           <form id = 'vendor_comment_form'>
           <div class="col-md-8">
          
            <textarea name="no_vendor_comment" id="no_vendor_comment" cols="30" rows="4" required class="form-control" placeholder='Enter comment for 0 vendor pay'><?php if(strlen($no_vendor_comment) > 0){ echo $no_vendor_comment; } ?></textarea>
            </div>
            <div class="col-md-1">
            <input type="submit" name="" required class="btn btn-success" id="">
            </div>
            </form>
            </div>
            <br>          
           </div>
           <div class="col-md-2"></div>
           <div class="col-md-5">
           <div class="row">
           <div class="col-md-3">
           <label for="">Vendor Pay<sup style='color:red;'>*</sup>:</label>
           </div>
           <form id= "invoice_vendor_pay_form">
            <div class="col-md-6">
            
            <input type="text" name="" placeholder="required" class="form-control" value = "<?php echo $invoice_vendor_pay; ?>" id="invoice_vendor_pay">
            </div>
            <div class="col-md-3">
            
            </div>
            </form>
        
            </div>
            <br>
            <div class="row">
           <div class="col-md-3">
           <label for="">Projected Profit:</label>
           </div>
           <div class="col-md-6">
            <input type="text" name="" disabled style = "<?php echo $projected_profit_color; ?>" class="form-control" value = "<?php echo $invoice_projected_profit; ?>" id="">
            </div>
            <div class="col-md-3">
           
            </div>
            </div>
           
            <?php if($show_client_pay == 'yes'){?>
            <br>
            <div class="row">
           <div class="col-md-3">
           <label for="">Client Pay:</label>
           </div>
           <form id= "invoice_vendor_client_form">
           <div class="col-md-6">
            <input type="text" name="" required class="form-control" value = "<?php echo $invoice_client_pay; ?>" id="invoice_client_pay">
            </div>
            <div class="col-md-3">
            <input type="submit" value="<?php if($invoice_client_pay > 0){echo 'Edit';}else{echo 'Add';} ?>"  name="" class="btn btn-success" id="">
           </div>
           </form>
        
            </div>
            <br>
            <div class="row">
           <div class="col-md-3">
           <label for="">Actual Profit:</label>
           </div>
           <div class="col-md-6">
            <input type="text" name="" disabled class="form-control" style = "<?php echo $actual_profit_color; ?>" value = "<?php echo $invoice_actual_profit; ?>" id="">
            </div>
            <div class="col-md-3">
           
           </div>
        
            </div>
           <?php } ?>
          
           </div>
           
           </div>   
          

            
            
                
                                    </div><!-- panel-body  -->
                 </div> <!-- panel panel-default -->
            </div> <!--  col lg 12-->
        </div> <!-- row -->
</div> <!--  page wrapper -->



</div>
    <!-- /#wrapper -->
    
    
    
<script src="js/jquery3.min.js"></script>
<script src="js/bootstrap.3.min.js"></script>    
<script src="js/jquery.dataTables1.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>
<!-- add Qty -->
<script type="text/javascript">
function addQtyIN(d){   

    var n = d;   
        
    var linker3 = "cellQ-" + n;               
    var linker5 = "totalQ-" + n;

    $.ajax({
        type: "POST",
        url: "in_add_qty_adata.php",
        data:'maps='+n+ '&in_no=<?php echo $invoice_id;?>',
        success: function(data){                      
            var reponse_qty1 = data;
            reponse_qty = JSON.parse(reponse_qty1);


            var bid_total_amount = reponse_qty.bid_amount;           

            var bid_item_total = reponse_qty.bid_item_total;           

            var bid_item_quantity = reponse_qty.bid_item_quantity;
                          
                
            document.getElementById(linker5).innerHTML = bid_item_total;
            document.getElementById(linker3).innerHTML = bid_item_quantity;
            document.getElementById("bid_total_amount").innerHTML = bid_total_amount;   

            var iframe = document.getElementById('iframe-modal');
            var tmp_src = iframe.src; 
            iframe.src = '';        
            iframe.src = tmp_src;
            location.reload(true);        
        }
    });     
}
</script>


 
<!-- /  add Qty -->
<!-- ======== -->
<!-- r Qty -->
<script type="text/javascript">
function remQtyIN(d){   

    var n = d;   
        
    var linker3 = "cellQ-" + n;               
    var linker5 = "totalQ-" + n;
    var linker2 = "rowQ-" + n;

    $.ajax({
        type: "POST",
        url: "in_rem_qty_adata.php",
        data:'maps='+n+ '&in_no=<?php echo $invoice_id;?>',
        success: function(data){                      
            var reponse_qty1 = data;
            reponse_qty = JSON.parse(reponse_qty1);


            var bid_total_amount = reponse_qty.bid_amount;

            var bid_item_total = reponse_qty.bid_item_total;

            var bid_item_quantity = reponse_qty.bid_item_quantity;
            if(bid_item_quantity == 0){
                $( "#"+ linker2 ).remove();
                document.getElementById("bid_total_amount").innerHTML = bid_total_amount;
            
            }else{                
                
            document.getElementById(linker5).innerHTML = bid_item_total;
            document.getElementById(linker3).innerHTML = bid_item_quantity;
            document.getElementById("bid_total_amount").innerHTML = bid_total_amount;
            }

            var iframe = document.getElementById('iframe-modal');
            var tmp_src = iframe.src; 
            iframe.src = '';        
            iframe.src = tmp_src;
            location.reload(true);
            
            
        }
    });     
}
</script>

 
<!-- /  r Qty -->

<script type="text/javascript">
function editItemN(d){
    var n = d;   
        
        var linker3 = "editItemForm-" + n;               
        var linker5 = "editItemSpan-" + n;
        var linker4 = "editItemDisplay-" + n;

        var elemxxx = document.querySelector('#' +linker3);
        elemxxx.style.display = 'block';
        var el = document.getElementById("inputItemForm" + n);
        $("#inputItemForm" + n).focus();
      
        if (typeof el.selectionStart == "number") {
            el.selectionStart = el.selectionEnd = el.value.length;
        } else if (typeof el.createTextRange != "undefined") {           
            var range = el.createTextRange();
            range.collapse(false);
            range.select();
        }
         
        var input = document.getElementById("inputItemForm" + n);
        input.addEventListener("keydown", function(event) {
            if (event.keyCode === 13) {
            event.preventDefault();
            document.getElementById("descEditsub"+ n).click();
            }
        });
    

        var elemxxx1 = document.querySelector('#' +linker5);
        elemxxx1.style.display = 'none';

        var elemxxx4 = document.querySelector('#' +linker4);
        elemxxx4.style.display = 'none';  

       
        

}


</script>

<script type="text/javascript">
function updateItemN(d){
    var n = d;

    var new_name = $("#inputItemForm" + n).val();  
    $.ajax({
        type: "POST",
        url: "in_update_name_adata.php",
        data:'maps=' + n + '&in_no=<?php echo $invoice_id;?>' + '&new_name=' + new_name,
        success: function(data){     
            var reponse_name = data;
            reponse_name = JSON.parse(reponse_name);

            var new_name = reponse_name.name;
            document.getElementById("editItemSpan-"+n).innerHTML = new_name;      
        }
    }); 
        
    var linker3 = "editItemForm-" + n;               
    var linker5 = "editItemSpan-" + n;
    var linker4 = "editItemDisplay-" + n;

    var elemxxx = document.querySelector('#' +linker3);
    elemxxx.style.display = 'none';

    var elemxxx1 = document.querySelector('#' +linker5);
    elemxxx1.style.display = 'block';  

    var elemxxx4 = document.querySelector('#' +linker4);
    elemxxx4.style.display = 'block';

    var iframe = document.getElementById('iframe-modal');
        var tmp_src = iframe.src; 
        iframe.src = '';        
        iframe.src = tmp_src;        
}


</script>

<!--  --> 

<script type="text/javascript">
function editItemP(d){
    <?php
       if($user_type == 'staff'){  
    ?>
    if(confirm("Are you sure you want to change item Price?")){

        <?php
       }
    ?>
    var n = d;   
        
    var linker3 = "editItemPForm-" + n;               
    var linker5 = "editItemPDisplay-" + n;

    var elemxxx = document.querySelector('#' +linker3);
    elemxxx.style.display = 'block';

    var elemxxx1 = document.querySelector('#' +linker5);
    elemxxx1.style.display = 'none';  
    <?php
    if($user_type == 'staff'){    ?>    
    }      
    <?php
      } 
    ?>        

}


</script>

<script>
$(function(){
    $(".bid_created").on('change', function(){
        var message_pri = $(".bid_created:checked").val();
            var linker6 = "bid_reason_details";

            var elemxxx11 = document.querySelector('#' +linker6);
            var linker5 = "bid_details";

            var elemxxx1 = document.querySelector('#' +linker5);

            
            var linker57 = "bid_amount_details";

            var elemxxx112 = document.querySelector('#' +linker57);
           

        if(message_pri == '1'){            
            elemxxx1.style.display = 'block';
            elemxxx11.style.display = 'none';            

        }else if(message_pri == '0'){ 
            elemxxx1.style.display = 'none';
            elemxxx112.style.display = 'none';
           
            elemxxx11.style.display = 'block';            
        }
    })
});

$("#bid_amount_form").submit(function() {

document.getElementById("bid_created_number").disabled = true; 
  var bid_created_number = $("#bid_created_number").val(); 

  var s = {
    "bid_created_number": bid_created_number,"invoice_number":"<?php echo $invoice_id;?>",   
  }

  $.ajax({
    url: 'invoice_bid_details_adata.php',
    type: 'POST',
    data: s,
    success: function(data) {
        var response_price = data.trim();
        response_price = JSON.parse(response_price);
        var message = response_price.message;
        if(message == 'missing'){
            var linker6 = "bid_amount_message";
            var elemxxx11 = document.querySelector('#' +linker6);           
            elemxxx11.style.display = 'block';        
            var amount = 'No Bid found with that Work Order# or Client / Property mismatch. Please Check';
            alert(amount);
            $('#bid_created_missing').html(amount); 
            location.reload(true);
           
            
            
            document.getElementById("bid_created_number").disabled = false; 
        }else if(message == 'found'){
            var linker6 = "bid_amount_details";
            var elemxxx11 = document.querySelector('#' +linker6);           
            elemxxx11.style.display = 'block';        
            var amount = response_price.amount;
            $('#bid_created_amount').val(amount);
            var linker6 = "bid_amount_message";
            var elemxxx11 = document.querySelector('#' +linker6);           
            elemxxx11.style.display = 'none'; 
            location.reload(true);
        }      
    } 
  });
  return false;
});
/*  */

$("#bid_reason_form").submit(function() {

document.getElementById("bid_created_number").disabled = true; 
  var no_bid_reason = $("#no_bid_reason").val(); 
  var s = {
    "no_bid_reason": no_bid_reason,"invoice_number":"<?php echo $invoice_id;?>",   
  }
  $.ajax({
    url: 'invoice_bid_details_adata.php',
    type: 'POST',
    data: s,
    success: function(data) {
        var response_price = data.trim();
        response_price = JSON.parse(response_price);
        var message = response_price.message
        if(message == 'reason_set'){
            var reason = response_price.reason;
            document.getElementById("no_bid_reason").disabled = true; 
            location.reload(true);
        }      
    } 
  });
  return false;
});
/*  */


$("#vendor_comment_form").submit(function() {

  var no_vendor_comment = $("#no_vendor_comment").val(); 
  var s = {
    "no_vendor_comment": no_vendor_comment,"invoice_number":"<?php echo $invoice_id;?>",   
  }
  $.ajax({
    url: 'invoice_bid_details_adata.php',
    type: 'POST',
    data: s,
    success: function(data) {
        var response_price = data.trim();
        response_price = JSON.parse(response_price);
        var message = response_price.message
        if(message == 'comment_set'){
            var reason = response_price.reason;
            document.getElementById("no_vendor_comment").disabled = true; 
            location.reload(true);
        }      
    } 
  });
  return false;
});


function delay(fn, ms) {
  let timer = 0
  return function(...args) {
    clearTimeout(timer)
    timer = setTimeout(fn.bind(this, ...args), ms || 0)
  }
}

$("#invoice_vendor_pay").keyup(delay(function (e) {
    if($(this).val().length > 0) {
        document.getElementById("invoice_vendor_pay").disabled = true; 
        var invoice_vendor_pay = $("#invoice_vendor_pay").val(); 
        var s = {
        "invoice_vendor_pay": invoice_vendor_pay,"invoice_number":"<?php echo $invoice_id;?>",   
        }
        $.ajax({
        url: 'invoice_bid_details_adata.php',
        type: 'POST',
        data: s,
        success: function(data){
            var response_price = data.trim();
            response_price = JSON.parse(response_price);
            var message = response_price.message
            if(message == 'vendor_pay_set'){
                location.reload(true); 
            }      
        } 
        });
        return false;
    }
}, 500));

/*  */

$("#invoice_vendor_client_form").submit(function() {

document.getElementById("invoice_client_pay").disabled = true; 
var invoice_client_pay = $("#invoice_client_pay").val(); 
var s = {
  "invoice_client_pay": invoice_client_pay,"invoice_number":"<?php echo $invoice_id;?>",   
}
$.ajax({
  url: 'invoice_bid_details_adata.php',
  type: 'POST',
  data: s,
  success: function(data){
      var response_price = data.trim();
      response_price = JSON.parse(response_price);
      var message = response_price.message
      if(message == 'client_pay_set'){
          location.reload(true); 
      }      
  } 
});
return false;
});

</script>

<script type="text/javascript">
function updateItemP(d){
    var n = d;
    var linker55 = "totalQ-" + n;
    var new_price = $("#inputItemPForm" + n).val();  
    $.ajax({
        type: "POST",
        url: "in_update_price_adata.php",
        data:'maps=' + n + '&in_no=<?php echo $invoice_id;?>' + '&new_price=' + new_price,
        success: function(data){     
            var response_price = data;
            response_price = JSON.parse(response_price);

            var new_price = response_price.price;
            document.getElementById("editItemPSpan-"+n).innerHTML = new_price; 

            var bid_total_amount = response_price.bid_amount;           

            var bid_item_total = response_price.bid_item_total;                                     
               
            document.getElementById(linker55).innerHTML = bid_item_total;
            
            document.getElementById("bid_total_amount").innerHTML = bid_total_amount; 
            location.reload(true);  
                 
        }
    }); 
        
        var linker3 = "editItemPForm-" + n;               
        var linker5 = "editItemPDisplay-" + n;

        var elemxxx = document.querySelector('#' +linker3);
        elemxxx.style.display = 'none';

        var elemxxx1 = document.querySelector('#' +linker5);
        elemxxx1.style.display = 'block';

        var iframe = document.getElementById('iframe-modal');
        var tmp_src = iframe.src; 
        iframe.src = '';        
        iframe.src = tmp_src;
}


</script>

 <!--  -->

<script>
    $(document).ready(function() {
        $('#dataTables-bidwizqwe2').DataTable({
          
            "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],          
           
        
        });
    });
</script>


<script>    
$(document).ready(function (e) {
    $(".form-image").on('submit',(function(e) {
        e.preventDefault();
        var $fileUpload = $("input[type='file']");

        const formData = new FormData(this);
        let jsonObject = {};

        for (const [key, value]  of formData.entries()) {
            jsonObject[key] = value;
        }
        
        
        var bid_item_ii = jsonObject.invoice_item_i;
        var cnt_rem_pic = 30 - jsonObject.rem_count;
        
        $.ajax({
            url: "in_item_actual_image_upload.php",
            type: "POST",
            data:  new FormData(this),
            contentType: false,
            cache: false,
            processData:false,
            beforeSend : function(){
                $("#err"+bid_item_ii).fadeOut();
                $("#uploading_i"+bid_item_ii).html("Uploading").fadeIn();                
                },
            success: function(data){
                var data = data.trim();
                if(data=='invalid1'){
                    $("#err"+bid_item_ii).html("Technical Problem. Code x0001").fadeIn();
                    $("#uploading_i"+bid_item_ii).fadeOut();
                    
                }else if(data=='invalid2'){
                    $("#err"+bid_item_ii).html("Technical Problem. Code x0002").fadeIn();
                    $("#uploading_i"+bid_item_ii).fadeOut();
                    
                }else if(data=='invalid3'){
                    $("#err"+bid_item_ii).html("You are only allowed to upload a maximum of 30 files").fadeIn();
                    $("#uploading_i"+bid_item_ii).fadeOut();
                    
                }else{                    
                    var trimData = data.trim();
                    var response_json = JSON.parse(trimData);
                    var bidId = response_json.bid_item_i;
                    var err_count = response_json.err_count;
                    var up_count = response_json.up_count;
                    var total_up = response_json.total_up;
                    var err_string = response_json.err_string;
                    var preview_start = response_json.preview_start;
                    var preview = response_json.preview;
                    if(up_count > 0){

                        for (i = 0; i < up_count; i++) {                            
                            var xi = Number(preview_start) + Number(i);
                            var img_pre = preview[i];                            
                            var elemxxx1 = document.querySelector("#ipreview"+ xi + "-" + bidId);
                            elemxxx1.style.display = 'block';
                            $("#preview"+ xi + "-" + bidId).html(img_pre).fadeIn();
                            var elemxxx2 = document.querySelector("#remove_i"+ xi + "-" + bidId);
                            elemxxx2.style.display = 'block';    
                            
                        } 
                        $("#uploading_i"+bid_item_ii).fadeOut(); 
                        
                        if(total_up == 30){
                            $("#uploadImagex"+ bidId).fadeOut();
                        }  
                        $('input[name="rem_count"]').val(total_up); 
                        $(".form-image")[0].reset();
                        
                    }
                    if(err_count > 0){
                        $(".form-image")[0].reset();  
                        $("#uploading_i"+bid_item_ii).fadeOut();                        
                        $("#err"+ bidId).html(err_string).fadeIn();

                    }                                              

                    var iframe = document.getElementById('iframe-modal');
                    var tmp_src = iframe.src; 
                    iframe.src = '';        
                    iframe.src = tmp_src;
                }
            },
            error: function(e){
                $("#err"+bid_item_ii).html(e).fadeIn();
                $("#uploading_i"+bid_item_ii).fadeOut();
            }          
        });  
    }));
});  
</script>



<script type="text/javascript">
function remPicWO(s){   
    var lin = s.split('-')[0];
    var n = s.split('-')[1];
    var linker11 = "remove_i" + lin +'-'+ n;             
    
    var linker12 = "preview" + lin +'-'+ n;                 
    $.ajax({
        type: "POST",
        url: "in_remove_pic_adata.php",
        data:'in_i='+n+'&i_no='+ lin,
        success: function(data){ 
            var trim_data = data.trim();
            $("#" + linker12).fadeOut();
            $("#" + linker11).fadeOut();
            $('input[name="rem_count"]').val(trim_data);
            location.reload(true);

            if(trim_data < 30){
                $("#uploadImagex"+ n).fadeIn();
            }
            var iframe = document.getElementById('iframe-modal');
            var tmp_src = iframe.src; 
            iframe.src = '';        
            iframe.src = tmp_src;            
        }
    });   
     
}
</script>

<script>
function setUoMval(value){

    var val1 = value.split('-')[1];
    var val2 = value.split('-')[0];
    
    if(val1 == 2){
        var lotSize = $("#bidin_uom_val1-" + val2).val();
        var grassheight = $("#bidin_uom_val2-" + val2).val();
        $.ajax({
        type: "POST",
        url: "in_uom_gc_adata.php",
        data:'in_i='+ val2 + '&uom_type='+ val1 + '&lot_size='+ lotSize + '&grass_height='+ grassheight,
        success: function(data){ 
                               
            var reponse_qty1 = data;
            reponse_qty1 = reponse_qty1.trim();
            if (reponse_qty1 == 'same'){
           
                
                document.getElementById("bidin_uom_val1-" + val2).disabled = true;
                document.getElementById("bidin_uom_val2-" + val2).disabled = true;


                var elemxxx = document.querySelector("#uomCalc-" + val2);
                elemxxx.style.display = 'none';

                var elemxxx1 = document.querySelector("#uomEdit-"+ val2);
                elemxxx1.style.display = 'block';
            
            }else{
                reponse_qty = JSON.parse(reponse_qty1);

                var bid_total_amount = reponse_qty.bid_amount;           

                var bid_item_total = reponse_qty.bid_item_total;
                var gc_cost = reponse_qty.gc_cost;

                var eq_cost = reponse_qty.eq_cost;
                var cutting_is_set = reponse_qty.cutting_is_set;

                var eq_is_set = reponse_qty.eq_is_set;


                var cutting_cost = reponse_qty.cutting_cost;


                var m_id = reponse_qty.m_id;             
                var linker5 = "totalQ-" + m_id;
                var linker10 = "uom2-gc-amount" + val2;

                var linker11 = "uom2-gc-eq-amount" + val2;
            

                var linker12 = "uom2-gc-cut-amount" + val2;
                            
                    
                document.getElementById(linker5).innerHTML = bid_item_total;

                document.getElementById(linker11).innerHTML = eq_cost;

                document.getElementById(linker12).innerHTML = cutting_cost;


                document.getElementById("bid_total_amount").innerHTML = bid_total_amount; 

                document.getElementById(linker10).innerHTML = gc_cost;

                document.getElementById("bidin_uom_val1-" + val2).disabled = true;
                document.getElementById("bidin_uom_val2-" + val2).disabled = true;

                if(cutting_is_set == 'set'){
                    var linker22 = document.querySelector("#row-uom2-cut" + val2);
                    linker22.style.display = 'block';
                    location.reload(true);

                }else if(cutting_is_set == 'unset'){
                    var linker23 = document.querySelector("#row-uom2-cut" + val2);
                    linker23.style.display = 'none';
                    location.reload(true);
                }

                if(eq_is_set == 'set'){
                    var linker24 = document.querySelector("#row-uom2-eq" + val2);
                    linker24.style.display = 'block';
                    location.reload(true);
                }else if(eq_is_set == 'unset'){
                    var linker25 = document.querySelector("#row-uom2-eq" + val2);
                    linker25.style.display = 'none';
                    location.reload(true);
                }


                var elemxxx = document.querySelector("#uomCalc-" + val2);
                elemxxx.style.display = 'none';

                var elemxxx1 = document.querySelector("#uomEdit-"+ val2);
                elemxxx1.style.display = 'block';
                var iframe = document.getElementById('iframe-modal');
                var tmp_src = iframe.src; 
                iframe.src = '';        
                iframe.src = tmp_src;  
                location.reload(true);
                }
            }
        });
    }else if(val1 == 4){
        var tarpArea = $("#bidin_uom_val1-" + val2).val();
        var tarpTime = $("#bidin_uom_val2-" + val2).val();        
        var tarpPitch = $("#bidin_uom_val3-" + val2).val();
        var tarpStorey = $("#bidin_uom_val4-" + val2).val();
        $.ajax({
        type: "POST",
        url: "in_uom_tarp_adata.php",
        data:'in_i='+ val2 + '&uom_type='+ val1 + '&tarpArea='+ tarpArea + '&tarpTime='+ tarpTime + '&tarpStorey='+ tarpStorey + '&tarpPitch='+ tarpPitch,
        success: function(data){ 
                               
            var reponse_qty1 = data;
            reponse_qty1 = reponse_qty1.trim();
            
            if (reponse_qty1 == 'same'){          
                
                document.getElementById("bidin_uom_val1-" + val2).disabled = true;
                document.getElementById("bidin_uom_val2-" + val2).disabled = true;


                var elemxxx = document.querySelector("#uomCalc-" + val2);
                elemxxx.style.display = 'none';

                var elemxxx1 = document.querySelector("#uomEdit-"+ val2);
                elemxxx1.style.display = 'block';
                location.reload(true);
           }else{
                reponse_qty = JSON.parse(reponse_qty1);


                var bid_total_amount = reponse_qty.bid_amount;           

                var bid_item_total = reponse_qty.bid_item_total;

                var m_id = reponse_qty.m_id;             
                var linker5 = "totalQ-" + m_id;
                            
                    
                document.getElementById(linker5).innerHTML = bid_item_total;
                document.getElementById("bid_total_amount").innerHTML = bid_total_amount; 

                document.getElementById("bidin_uom_val1-" + val2).disabled = true;
                document.getElementById("bidin_uom_val2-" + val2).disabled = true;


                var elemxxx = document.querySelector("#uomCalc-" + val2);
                elemxxx.style.display = 'none';

                var elemxxx1 = document.querySelector("#uomEdit-"+ val2);
                elemxxx1.style.display = 'block';
                /* here */
                var iframe = document.getElementById('iframe-modal');
            var tmp_src = iframe.src; 
            iframe.src = '';        
            iframe.src = tmp_src;   
            location.reload(true);
           }
        }
        });
    }else if(val1 == 1){
        var length = $("#bidin_uom_val1-" + val2).val();
        var width = $("#bidin_uom_val2-" + val2).val();        
        $.ajax({
        type: "POST",
        url: "in_uom_sf_adata.php",
        data:'in_i='+ val2 + '&uom_type='+ val1 + '&length='+ length + '&width='+ width,
        success: function(data){                               
            var reponse_qty1 = data;
            reponse_qty1 = reponse_qty1.trim();            
            if (reponse_qty1 == 'same'){       
                document.getElementById("bidin_uom_val1-" + val2).disabled = true;
                document.getElementById("bidin_uom_val2-" + val2).disabled = true;

                var elemxxx = document.querySelector("#uomCalc-" + val2);
                elemxxx.style.display = 'none';

                var elemxxx1 = document.querySelector("#uomEdit-"+ val2);
                elemxxx1.style.display = 'block';
           }else{
                reponse_qty = JSON.parse(reponse_qty1);
                var bid_total_amount = reponse_qty.bid_amount;
                var bid_item_total = reponse_qty.bid_item_total;
                var bid_item = reponse_qty.bid_item;

                var m_id = reponse_qty.m_id;             
                var linker5 = "totalQ-" + m_id;
                var linker55 = "totalI-" + m_id;
                document.getElementById(linker5).innerHTML = bid_item_total;
                document.getElementById(linker55).innerHTML = bid_item;
                document.getElementById("bid_total_amount").innerHTML = bid_total_amount; 

                document.getElementById("bidin_uom_val1-" + val2).disabled = true;
                document.getElementById("bidin_uom_val2-" + val2).disabled = true;
              
                var elemxxx = document.querySelector("#uomCalc-" + val2);
                elemxxx.style.display = 'none';

                var elemxxx1 = document.querySelector("#uomEdit-"+ val2);
                elemxxx1.style.display = 'block';
                
                var iframe = document.getElementById('iframe-modal');
                var tmp_src = iframe.src; 
                iframe.src = '';        
                iframe.src = tmp_src;   
           }
 


        }
    });
    }else if(val1 == 5){
        var time = $("#bidin_uom_val1-" + val2).val();
        $.ajax({
        type: "POST",
        url: "in_uom_hour_adata.php",
        data:'in_i='+ val2 + '&uom_type='+ val1 + '&time='+ time,
        success: function(data){                               
            var reponse_qty1 = data;
            reponse_qty1 = reponse_qty1.trim();            
            if (reponse_qty1 == 'same'){       
                document.getElementById("bidin_uom_val1-" + val2).disabled = true;
                var elemxxx = document.querySelector("#uomCalc-" + val2);
                elemxxx.style.display = 'none';

                var elemxxx1 = document.querySelector("#uomEdit-"+ val2);
                elemxxx1.style.display = 'block';
           }else{
                reponse_qty = JSON.parse(reponse_qty1);
                var bid_total_amount = reponse_qty.bid_amount;
                var bid_item_total = reponse_qty.bid_item_total;
                var bid_item = reponse_qty.bid_item;

                var m_id = reponse_qty.m_id;             
                var linker5 = "totalQ-" + m_id;
                var linker55 = "totalI-" + m_id;
                document.getElementById(linker5).innerHTML = bid_item_total;
                document.getElementById(linker55).innerHTML = bid_item;
                document.getElementById("bid_total_amount").innerHTML = bid_total_amount; 

                document.getElementById("bidin_uom_val1-" + val2).disabled = true;
              
                var elemxxx = document.querySelector("#uomCalc-" + val2);
                elemxxx.style.display = 'none';

                var elemxxx1 = document.querySelector("#uomEdit-"+ val2);
                elemxxx1.style.display = 'block';
                
                var iframe = document.getElementById('iframe-modal');
                var tmp_src = iframe.src; 
                iframe.src = '';        
                iframe.src = tmp_src;   
           }
        }
    });
    }else if(val1 == 8){
        var time = $("#bidin_uom_val1-" + val2).val();
        $.ajax({
        type: "POST",
        url: "in_uom_lf_adata.php",
        data:'in_i='+ val2 + '&uom_type='+ val1 + '&time='+ time,
        success: function(data){                               
            var reponse_qty1 = data;
            reponse_qty1 = reponse_qty1.trim();            
            if (reponse_qty1 == 'same'){       
                document.getElementById("bidin_uom_val1-" + val2).disabled = true;
                var elemxxx = document.querySelector("#uomCalc-" + val2);
                elemxxx.style.display = 'none';

                var elemxxx1 = document.querySelector("#uomEdit-"+ val2);
                elemxxx1.style.display = 'block';
           }else{
                reponse_qty = JSON.parse(reponse_qty1);
                var bid_total_amount = reponse_qty.bid_amount;
                var bid_item_total = reponse_qty.bid_item_total;
                var bid_item = reponse_qty.bid_item;

                var m_id = reponse_qty.m_id;             
                var linker5 = "totalQ-" + m_id;
                var linker55 = "totalI-" + m_id;
                document.getElementById(linker5).innerHTML = bid_item_total;
                document.getElementById(linker55).innerHTML = bid_item;
                document.getElementById("bid_total_amount").innerHTML = bid_total_amount; 

                document.getElementById("bidin_uom_val1-" + val2).disabled = true;
              
                var elemxxx = document.querySelector("#uomCalc-" + val2);
                elemxxx.style.display = 'none';

                var elemxxx1 = document.querySelector("#uomEdit-"+ val2);
                elemxxx1.style.display = 'block';
                
                var iframe = document.getElementById('iframe-modal');
                var tmp_src = iframe.src; 
                iframe.src = '';        
                iframe.src = tmp_src;   
           }
        }
    });
    }else if(val1 == 6){
        var length = $("#bidin_uom_val1-" + val2).val();
        var width = $("#bidin_uom_val2-" + val2).val();        
        $.ajax({
        type: "POST",
        url: "in_uom_ui_adata.php",
        data:'in_i='+ val2 + '&uom_type='+ val1 + '&length='+ length + '&width='+ width,
        success: function(data){                               
            var reponse_qty1 = data;
            reponse_qty1 = reponse_qty1.trim();            
            if (reponse_qty1 == 'same'){       
                document.getElementById("bidin_uom_val1-" + val2).disabled = true;
                document.getElementById("bidin_uom_val2-" + val2).disabled = true;

                var elemxxx = document.querySelector("#uomCalc-" + val2);
                elemxxx.style.display = 'none';

                var elemxxx1 = document.querySelector("#uomEdit-"+ val2);
                elemxxx1.style.display = 'block';
           }else{
                reponse_qty = JSON.parse(reponse_qty1);
                var bid_total_amount = reponse_qty.bid_amount;
                var bid_item_total = reponse_qty.bid_item_total;
                var bid_item = reponse_qty.bid_item;

                var m_id = reponse_qty.m_id;             
                var linker5 = "totalQ-" + m_id;
                var linker55 = "totalI-" + m_id;
                document.getElementById(linker5).innerHTML = bid_item_total;
                document.getElementById(linker55).innerHTML = bid_item;
                document.getElementById("bid_total_amount").innerHTML = bid_total_amount; 

                document.getElementById("bidin_uom_val1-" + val2).disabled = true;
                document.getElementById("bidin_uom_val2-" + val2).disabled = true;
              
                var elemxxx = document.querySelector("#uomCalc-" + val2);
                elemxxx.style.display = 'none';

                var elemxxx1 = document.querySelector("#uomEdit-"+ val2);
                elemxxx1.style.display = 'block';
                
                var iframe = document.getElementById('iframe-modal');
                var tmp_src = iframe.src; 
                iframe.src = '';        
                iframe.src = tmp_src;   
           }
 


        }
    });
    }else if(val1 == 7){
        var length = $("#bidin_uom_val1-" + val2).val();
        var width = $("#bidin_uom_val2-" + val2).val();        
        var height = $("#bidin_uom_val3-" + val2).val(); 
        $.ajax({
        type: "POST",
        url: "in_uom_cyd_adata.php",
        data:'in_i='+ val2 + '&uom_type='+ val1 + '&length='+ length + '&width='+ width + '&height='+ height,
        success: function(data){                               
            var reponse_qty1 = data;
            reponse_qty1 = reponse_qty1.trim();            
            if (reponse_qty1 == 'same'){       
                document.getElementById("bidin_uom_val1-" + val2).disabled = true;
                document.getElementById("bidin_uom_val2-" + val2).disabled = true;
                document.getElementById("bidin_uom_val3-" + val2).disabled = true;
                var elemxxx = document.querySelector("#uomCalc-" + val2);
                elemxxx.style.display = 'none';

                var elemxxx1 = document.querySelector("#uomEdit-"+ val2);
                elemxxx1.style.display = 'block';
           }else{
                reponse_qty = JSON.parse(reponse_qty1);
                var bid_total_amount = reponse_qty.bid_amount;
                var bid_item_total = reponse_qty.bid_item_total;
                var bid_item = reponse_qty.bid_item;

                var m_id = reponse_qty.m_id;             
                var linker5 = "totalQ-" + m_id;
                var linker55 = "totalI-" + m_id;
                document.getElementById(linker5).innerHTML = bid_item_total;
                document.getElementById(linker55).innerHTML = bid_item;
                document.getElementById("bid_total_amount").innerHTML = bid_total_amount; 

                document.getElementById("bidin_uom_val1-" + val2).disabled = true;
                document.getElementById("bidin_uom_val2-" + val2).disabled = true;
                document.getElementById("bidin_uom_val3-" + val2).disabled = true;

                var elemxxx = document.querySelector("#uomCalc-" + val2);
                elemxxx.style.display = 'none';

                var elemxxx1 = document.querySelector("#uomEdit-"+ val2);
                elemxxx1.style.display = 'block';
                
                var iframe = document.getElementById('iframe-modal');
                var tmp_src = iframe.src; 
                iframe.src = '';        
                iframe.src = tmp_src;   
           }
        }
    });
    }


}
</script>

    <script>
function unsetUoMval(value){

    var n = value;           
    var linker3 = "uomCalc-" + n;               
    var linker5 = "uomEdit-" + n;

    var elemxxx = document.querySelector('#' +linker3);
    elemxxx.style.display = 'block';

    var elemxxx1 = document.querySelector('#' +linker5);
    elemxxx1.style.display = 'none';

    document.getElementById("bidin_uom_val1-" + n).disabled = false;
    document.getElementById("bidin_uom_val2-" + n).disabled = false;

}


function unsetUoMval4(value){

var n = value;           
var linker3 = "uomCalc-" + n;               
var linker5 = "uomEdit-" + n;

var elemxxx = document.querySelector('#' +linker3);
elemxxx.style.display = 'block';

var elemxxx1 = document.querySelector('#' +linker5);
elemxxx1.style.display = 'none';

document.getElementById("bidin_uom_val1-" + n).disabled = false;
document.getElementById("bidin_uom_val2-" + n).disabled = false;
document.getElementById("bidin_uom_val3-" + n).disabled = false;
document.getElementById("bidin_uom_val4-" + n).disabled = false;


}
function unsetUoMval3(value){

var n = value;           
var linker3 = "uomCalc-" + n;               
var linker5 = "uomEdit-" + n;

var elemxxx = document.querySelector('#' +linker3);
elemxxx.style.display = 'block';

var elemxxx1 = document.querySelector('#' +linker5);
elemxxx1.style.display = 'none';

document.getElementById("bidin_uom_val1-" + n).disabled = false;
document.getElementById("bidin_uom_val2-" + n).disabled = false;
document.getElementById("bidin_uom_val3-" + n).disabled = false;
}
function unsetUoMval1(value){

var n = value;           
var linker3 = "uomCalc-" + n;               
var linker5 = "uomEdit-" + n;

var elemxxx = document.querySelector('#' +linker3);
elemxxx.style.display = 'block';

var elemxxx1 = document.querySelector('#' +linker5);
elemxxx1.style.display = 'none';

document.getElementById("bidin_uom_val1-" + n).disabled = false;
}
</script>
<script>
function remItemRN(valueIn){
    var wholeValue = $("#remJSON-" + valueIn).val();
    var trmWholeValue = wholeValue.trim();  
    var parseWholeValue = JSON.parse(trmWholeValue);
    var maps = parseWholeValue.maps; 
    var cl_id = parseWholeValue.cl_id;
    var in_no = parseWholeValue.in_no;
    var invoice_no = parseWholeValue.invoice_no;
    var state = parseWholeValue.state;
    var linker2 = "rowQ-" + maps;


    $.ajax({
        type: "POST",
        url: "in_rem_item_adata_total.php",
        data:'maps='+maps+'&cl_id='+cl_id+'&in_no='+in_no+'&invoice_no='+invoice_no+'&state='+state,
        success: function(data){           
            var reponse = data.trim();
            reponse_json = JSON.parse(reponse);
            var status = reponse_json.status; 

            if(status == 'done'){
                var bid_total_amount = reponse_json.bid_amount; 

                document.getElementById("bid_total_amount").innerHTML = bid_total_amount;

                $( "#"+ linker2 ).remove();
            }else if(status == 'delete'){
                $( "#"+ linker2 ).remove();
            }
            location.reload(true);

        }
    });

    
}
</script>
<?php include_once "search_footer.php" ?>
</body>
</html>
