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

if(isset($_REQUEST['in_no'])&& isset($_REQUEST['invoice_no']) && isset($_REQUEST['state']) && isset($_REQUEST['client_id'])){
    if(strlen($_REQUEST['in_no'])>0 && strlen($_REQUEST['invoice_no'])>0 && strlen($_REQUEST['state'])>0 && strlen($_REQUEST['client_id'])>0){
        $invoice_id = $_REQUEST['in_no'];
        $invoice_no = $_REQUEST['invoice_no'];
        $state = $_REQUEST['state'];
        $url_client_id = $_REQUEST['client_id'];
        $url_client_id1 = $url_client_id;
        $check_client_list = "SELECT * FROM client WHERE client_id = $url_client_id AND is_list IS NULL";
        $check_client_list_run = mysqli_query($conn, $check_client_list);

        if(mysqli_num_rows($check_client_list_run)>0){
            $url_client_id =0;
        }
    }else{
        header("Location:index.php");        
    }   
    
}else{
    header("Location:index.php");    
}
$query_cat_find1v = "SELECT * FROM category WHERE cat_approved = 1 AND cat_is_delete IS NULL ORDER BY cat_id ASC";
$run_cat_find1v = mysqli_query($conn, $query_cat_find1v);
$setr = 'no';
if(mysqli_num_rows($run_cat_find1v) >0){
  while($row_cat_find1v = mysqli_fetch_array($run_cat_find1v)){
    $cat_id = $row_cat_find1v['cat_id'];

    $query_maps_find1v = "SELECT * FROM maps WHERE client_id = $url_client_id AND cat_id = $cat_id AND maps_approved = 1 AND maps_is_delete IS NULL";
    $run_maps_find1v = mysqli_query($conn, $query_maps_find1v);
    if(mysqli_num_rows($run_maps_find1v) >0){
        if($setr == 'no'){
           $min_cat_id = $cat_id;
            $setr = 'yes';
        }
    }
  }
}
$url_cat_id = $min_cat_id;

$query_client_find1 = "SELECT * FROM client WHERE client_id = $url_client_id1 AND is_approve = 1 AND client_is_delete IS NULL";

$run_client_find1 = mysqli_query($conn, $query_client_find1);

if(mysqli_num_rows($run_client_find1)>0){
    while($row_client_find1 = mysqli_fetch_array($run_client_find1)){
        $client_alias = $row_client_find1['client_alias'];
    }
}
include "header.php";
?>

<div id="page-wrapper">
<h3 style = "color:#0b57a4; font-weight:bold;padding-bottom:4px;margin-bottom:0;text-align:center">INVOICE</h3>
<a class='btn btn-primary' href='index.php' id = 'wo_state_1_save'>Save and Exit</a>&nbsp&nbsp<a class='btn btn-success' href='invoice_finalize.php?in_no=<?php echo $invoice_id;?>' id = 'wo_state_1_next'>Next</a>&nbsp&nbsp<a class='btn btn-warning' href='index.php' id = 'wo_state_1_cancel'>Cancel</a><br>
<h3><span id = "wo_state_1_counter"><?php $check_wo_state1_query = "SELECT * FROM invoice_item WHERE invoice_id = $invoice_id";
        $check_wo_state1_run = mysqli_query($conn, $check_wo_state1_query);
         echo mysqli_num_rows($check_wo_state1_run);?></span> Items - Invoice# <?php echo $invoice_no;?> - <?php echo $client_alias;?></h3>

<!-- -->

<ul data-tabs>
<li><a <?php

           if($url_client_id ==0){

               echo "data-tabby-default";
               $client_id_tab_check = 'unset';

            }else{
                $client_id_tab_check = 'set';
            }



            ?> href="#nqew00" id = "clientq_id_0">Main</a></li>

<?php
if($client_id_tab_check == 'set'){
$query_client_find = "SELECT * FROM client WHERE is_approve = 1 AND client_is_delete IS NULL AND is_list = 1 AND client_id = $url_client_id";

$run_client_find = mysqli_query($conn, $query_client_find);

if(mysqli_num_rows($run_client_find)>0){

 while($row_client_find = mysqli_fetch_array($run_client_find)){
    $client_id_t =  $row_client_find['client_id'];
    $client_id_tab = "clientq_id_" . $client_id_t;
    $client_alias = $row_client_find['client_alias'];?>
        <li><a <?php
       
                echo "data-tabby-default ";
                $client_id_tab_check = 'unset';
           
            ?>href="#nqew<?php echo $client_id_t.$client_id_t ?>" id="<?php echo $client_id_tab ?>"><?php echo $client_alias ?></a></li>
    <?php
   }
}
}
?>


</ul>

        <!--  active div (div start)-->
<?php
/* $url_client_id */
if($url_client_id == 0){
    echo '<div id="nqew00">';
}else{
    echo '<div id="nqew00">';
    echo '<div id="oqld00">';
    echo "<p>Loading</p>";
    echo '</div>';
    echo '</div>';



$query_client_find1 = "SELECT * FROM client WHERE client_id = $url_client_id AND is_approve = 1 AND client_is_delete IS NULL AND is_list = 1";

$run_client_find1 = mysqli_query($conn, $query_client_find1);

if(mysqli_num_rows($run_client_find1)>0){

 while($row_client_find1 = mysqli_fetch_array($run_client_find1)){
    $client_id_tab21 = $row_client_find1['client_id'];

   ?>
        <div id="nqew<?php echo $client_id_tab21.$client_id_tab21?>">

    <?php }
}

}
?>
<!--   -->
<!-- cat -->

<ul data-tabsx>

<?php
$query_cat_find = "SELECT * FROM category WHERE cat_approved = 1 AND cat_is_delete IS NULL";

$run_cat_find = mysqli_query($conn, $query_cat_find);
$cat_id_tab_check = 'set';
if(mysqli_num_rows($run_cat_find)>0){

 while($row_cat_find = mysqli_fetch_array($run_cat_find)){
    $cat_id =  $row_cat_find['cat_id'];
    $cat_name =  $row_cat_find['cat_name'];

    $query_cat_search = "SELECT * FROM maps WHERE client_id = $url_client_id AND cat_id = $cat_id AND maps_approved = 1 AND maps_is_delete IS NULL";

    $run_cat_search = mysqli_query($conn, $query_cat_search);

    if(mysqli_num_rows($run_cat_search)>0){
        $cat_id_tab = "catid_". $cat_id."-" .$url_client_id;?>
            <li><a <?php

                if($cat_id_tab_check == 'set'){
                    echo "data-tabby-default ";
                    $cat_id_tab_check = 'unset';
                }


    ?>href="#ncew<?php echo $cat_id.$cat_id.$url_client_id ?>" style = "color: #0b57a4" id="<?php echo $cat_id_tab ?>"><?php echo $cat_name;  ?></a></li>
    <?php  }
   }
}
?>


</ul>
<!-- /cat-->
<!-- /cat cont loop-->
<?php
/* $url_client_id */
if($url_cat_id == $min_cat_id){
    echo "<div id='ncew$min_cat_id$min_cat_id$url_client_id'>";
}else{
    echo "<div id='ncew$min_cat_id$min_cat_id$url_client_id'>";
    echo "<div id='ocld$min_cat_id$min_cat_id$url_client_id'>";
    echo "<p>Loading</p>";
    echo '</div>';
    echo '</div>';

$query_cat_find = "SELECT * FROM category WHERE cat_id < $url_cat_id AND cat_approved = 1 AND cat_is_delete IS NULL";

$run_cat_find = mysqli_query($conn, $query_cat_find);

if(mysqli_num_rows($run_cat_find)>0){

 while($row_cat_find = mysqli_fetch_array($run_cat_find)){

    $cat_id_tab2 = $row_cat_find['cat_id'];
    $searchcat_maps = "SELECT * FROM maps WHERE cat_id = $cat_id_tab2 AND client_id = $url_client_id AND maps_approved = 1 AND maps_is_delete IS NULL";
    $runsearchcat_maps = mysqli_query($conn, $searchcat_maps);

    if(mysqli_num_rows($runsearchcat_maps)>0){

   ?>
        <div id="ncew<?php echo $cat_id_tab2.$cat_id_tab2.$url_client_id?>">
        <div id="ocld<?php echo $cat_id_tab2.$cat_id_tab2.$url_client_id?>">

        <p>Loading</p>
        </div>

        </div>
    <?php }}
}

$query_cat_find1 = "SELECT * FROM category WHERE cat_id = $url_cat_id AND cat_approved = 1 AND cat_is_delete IS NULL";

$run_cat_find1 = mysqli_query($conn, $query_cat_find1);

if(mysqli_num_rows($run_cat_find1)>0){

 while($row_cat_find1 = mysqli_fetch_array($run_cat_find1)){
    $cat_id_tab21 = $row_cat_find1['cat_id'];

   ?>
        <div id="ncew<?php echo $cat_id_tab21.$cat_id_tab21.$url_client_id?>">

    <?php }//while
}//if

}
?>
<!-- /cat cont loop -->


<br>
     <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
            <div class="panel-body">
                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-bidwizlist<?php $random_num = mt_rand(10,99).time();
                            echo $random_num;
                            ?>">
                                    <thead>
                                        <tr>
                                        <th>
                                                Add / Remove
                                                </th>
                                                <th>
                                                Job Task
                                                </th>
                                                <th>
                                                Reference Photo
                                                </th>

                                                <th>
                                                Description
                                                </th>
                                                <th>
                                    Client Allowable Price                                                </th>

                                            <th>Price</th>
                                            <th>Crew Pay</th>
                                            <th>UOM</th>
                                            <th>Photo Requirements</th>
                                            </tr>
                                        </thead>
                                        <tbody>
<?php
    if($conn){

       $query = "SELECT * FROM maps LEFT JOIN category
        ON maps.cat_id = category.cat_id  WHERE maps.cat_id = $min_cat_id  AND maps.client_id = $url_client_id AND maps.maps_is_delete IS NULL AND maps.maps_approved = 1 ORDER BY category.cat_name";
        $run = mysqli_query($conn, $query);

        if(mysqli_num_rows($run)>0){
            while($row = mysqli_fetch_array($run)){
                $maps_id = $row['maps_id'];
                $check_set = "SELECT * FROM invoice_item WHERE maps_id = $maps_id AND invoice_id = $invoice_id and is_delete IS NULL";

                $run_check_set = mysqli_query($conn, $check_set);
                if(mysqli_num_rows($run_check_set)>0){
                    $set = 'set';
                }

                $ref_photo = $row['maps_ref_pic'];
                $cat_name = $row['cat_name'];
                $maps_name = $row['maps_name'];
                $description = $row['maps_desc'];
                $client_allow_price = $row['maps_client_allow_price'];
                $min_invoice_price = $row['maps_min_bid_price'];
                $crew_pay = $row['maps_crew_pay'];
                $photo_req = $row['maps_photo_req'];
                $maps_uom =$row['maps_crew_unit_uom_id'];
if($maps_uom == NULL){

}else{
    $query22 = "SELECT uom_name FROM uom WHERE uom_id = $maps_uom";

    $run22 = mysqli_query($conn, $query22);
if(mysqli_num_rows($run22)==1){
$row22 = mysqli_fetch_array($run22);

$maps_uom = $row22['uom_name'];
}
}
                echo '<tr class="odd gradeX">';

               
if($set =='set'){
    echo '<td><a href="#" class="btn btn-success hidden" id = "add-'.$maps_id.'">+</a><br><a href="#" class="btn btn-danger"  id = "rem-'.$maps_id.'">Remove</a></td>';
    $set = '';
}else{
echo '<td><a href="#" class="btn btn-success" id = "add-'.$maps_id.'">+</a><br><a href="#" class="btn btn-danger hidden"  id = "rem-'.$maps_id.'">Remove</a></td>';}


                echo '<td>' .$maps_name. '</td>';
                echo '<td><img src = "maps_ref_image.php?i='.$ref_photo.'" height = "80px" width = "120px">'. '</td>';


                echo '<td>' .$description. '</td>';
                echo '<td>' .$client_allow_price. '</td>';
                echo '<td>' .$min_invoice_price. '</td>';
                echo '<td>' .$crew_pay. '</td>';
                echo '<td>' .$maps_uom. '</td>';
                 echo '<td>' .$photo_req. '</td>';
                echo '</tr>';
            }
        }

    }

?>

                                            </tbody>

                                    </table>

                                    </div><!-- panel-body  -->
                 </div> <!-- panel panel-default -->
            </div> <!--  col lg 12-->
        </div> <!-- row -->
 <!-- cat content close-->

 <?php
if($url_cat_id == $min_cat_id){?>
 </div>
  <!--  active div (div end)-->
<?php
   $query_cat_find3qw = "SELECT * FROM category WHERE cat_id > $url_cat_id AND cat_approved = 1 AND cat_is_delete IS NULL";

   $run_cat_find3qw = mysqli_query($conn, $query_cat_find3qw);

   if(mysqli_num_rows($run_cat_find3qw)>0){

       while($row_cat_find3qw = mysqli_fetch_array($run_cat_find3qw)){
          $cat_id_tab23qw = $row_cat_find3qw['cat_id'];
           $query_cat_find123qw = "SELECT * FROM maps WHERE cat_id = $cat_id_tab23qw AND client_id = $url_client_id AND maps_approved = 1 AND maps_is_delete IS NULL";
           $run_cat_find123qw = mysqli_query($conn, $query_cat_find123qw);


           if(mysqli_num_rows($run_cat_find123qw) > 0){

           ?>


           <div id="ncew<?php echo $cat_id_tab23qw.$cat_id_tab23qw.$url_client_id?>">
           <div id="ocld<?php echo $cat_id_tab23qw.$cat_id_tab23qw.$url_client_id?>">

           <p>Loading</p>
           </div>

           </div>
<?php }
}
   }


    }else{
        echo "</div><!--  active div (div end)-->";

        $query_cat_find321 = "SELECT * FROM category WHERE cat_id > $url_cat_id AND cat_approved = 1 AND cat_is_delete IS NULL";

        $run_cat_find321 = mysqli_query($conn, $query_cat_find321);

        if(mysqli_num_rows($run_cat_find321)>0){

            while($row_cat_find321 = mysqli_fetch_array($run_cat_find321)){
                $cat_id_tab2x3 = $row_cat_find321['cat_id'];?>
                <div id="ncew<?php echo $cat_id_tab2x3.$cat_id_tab2x3.$url_client_id?>">
                <div id="ocld<?php echo $cat_id_tab2x3.$cat_id_tab2x3.$url_client_id?>">

                <p>Loading</p>
                </div>

                </div>
    <?php }

        }
    }
?>



 <!-- /cat idcontetn close-->

<?php
if($url_client_id == 0){?>
 </div>
  <!--  active div (div end)-->

<?php 
    }else{
        echo "</div><!--  active div (div end)-->";

    }
?>




    </div> <!--  page wrapper -->


        <script>
    var deleteLinks = document.querySelectorAll('.delete');

for (var i = 0; i < deleteLinks.length; i++) {
  deleteLinks[i].addEventListener('click', function(event) {
	  event.preventDefault();

	  var choice = confirm(this.getAttribute('data-confirm'));

	  if (choice) {
	    window.location.href = this.getAttribute('href');
	  }
  });
}
    </script>
    <script>
    function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $('#upload')
                        .attr('src', e.target.result)
                        .width(600)
                        .height(300);
                };

                reader.readAsDataURL(input.files[0]);
            }
        }
    </script>
</div>
    <!-- /#wrapper -->


    
    <script>
var deleteLinks = document.querySelectorAll('.delete');

for (var i = 0; i < deleteLinks.length; i++) {
deleteLinks[i].addEventListener('click', function(event) {
  event.preventDefault();

  var choice = confirm(this.getAttribute('data-confirm'));

  if (choice) {
    window.location.href = this.getAttribute('href');
  }
});
}
</script>
<script>
function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();

            reader.onload = function (e) {
                $('#upload')
                    .attr('src', e.target.result)
                    .width(300)
                    .height(150);
            };

            reader.readAsDataURL(input.files[0]);
        }
    }
</script>
    
   <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>
    
    <script src="js/tabby.min.js"></script>
    <script>
		var tabs = new Tabby('[data-tabs]');
	</script>
 <script>
		var tabsx = new Tabby('[data-tabsx]');

	</script>


<script type="text/javascript">
function fetchClientData(d){
    var a = document.getElementById(d);
    if(typeof(a) != 'undefined' || a != null){ 
    a.onclick = function() {
        var n = d.substr(10);
        n1 = "new" +n+n;
        n2 = "old" +n+n;  

        if(typeof(n) != 'undefined' || n != null){   
        $.ajax({
        type: "POST",
        url: "client_price_list_adata.php",
        data:'cl_id='+n,
        success: function(data){
            $("#"+n1).html(data);
            $("#"+n2).hide();

       
        $('#dataTables-bidwiz'+n1).DataTable({
            responsive: true,
           
        
        });


       

       
        $('#dataTables-bidwiz'+n2).DataTable({
            responsive: true,
            "order": [[ 0, "desc" ]],
            dom: 'Bfrtip',
        buttons: [
            'copyHtml5',
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
        });

        }
        });
    }

          return true;
    }   
}
}
</script> 

<script>
   $(document).ready(function() {
        $('#dataTables-bidwiz12333').DataTable({
            responsive: true,           
            "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
          
            "ordering":false,
        buttons: [
            'copyHtml5',
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
        });
    });
    </script>

 <?php

$query = "SELECT * FROM client WHERE is_approve = 1 AND client_is_delete IS NULL AND is_list = 1";

$run = mysqli_query($conn, $query);

if(mysqli_num_rows($run)>0){
    echo "<script>";
    $c = 1;
    while($row = mysqli_fetch_array($run)){
    $client_id = $row['client_id'];
    $s = $c + 1;
    $c = 'var c'.$s;

    echo $c . ' = "client_id_'. $client_id .'";';
    

    echo 'fetchClientData(c' .$s. ');';

   }

   
   echo 'var cxx0 = "client_id_0";';
    echo 'fetchClientData(cxx0);';
  
  echo "</script>"; 

}


?> 


 <?php

// $query = "SELECT * FROM client WHERE is_approve = 1 AND client_is_delete IS NULL AND is_list = 1";

// $run = mysqli_query($conn, $query);

// if(mysqli_num_rows($run)>0){
//     echo "<script>";
//     $c = 1;
//     while($row = mysqli_fetch_array($run)){
//     $client_id = $row['client_id'];
//     $s = $c + 1;
//     $c = 'var c'.$s;

//     echo $c . ' = "clientq_id_'. $client_id .'";';
    

//     echo 'fetchClientItemData(c' .$s. ');';

//    }

   
//    echo 'var cxx0 = "clientq_id_0";';
//     echo 'fetchClientItemData(cxx0);';
  
//   echo "</script>"; 

// }
?> 

<!-- /  price1 -->


    <script>
    function hideRowUOM() {
        var val3 = document.getElementById("maps_uom").value;
        if(val3 == ''){
            var elemxxx = document.querySelector('#UOMsetDeleteRow');
elemxxx.style.display = 'block';
        }else{
    var elemxxx = document.querySelector('#UOMsetDeleteRow');
elemxxx.style.display = 'none';}
 
}

function getUOMvalue() {
  var val1 = document.getElementById("maps_uom");
  val1 = val1.value;    
  var val2 = document.getElementById("maps_id");  
  if(typeof(val2) == 'undefined' || val2 == null){
        val2 = '';
    }else{
        val2 = val2.value;
    }
  $.ajax({
  type: "POST",
  url: "get_uom_value.php",
  data:'maps_uom_id='+val1+'&maps_id='+val2,
  success: function(data){
    $("#displayUOMvalueForm").html(data);
  }
  });

  hideRowUOM();
}
function getUOMvalue3() {
  var val1 = document.getElementById("maps_uom").value;
 
  
  $.ajax({
  type: "POST",
  url: "get_uom_value.php",
  data:'maps_uom_id='+val1+'&maps_id=',
  success: function(data){
    $("#displayUOMvalueForm").html(data);
  }
  });

  hideRowUOM();
}



function getUOMvalue1() {
  var val1 = document.getElementById("maps_uom");
  val1 = val1.value;    
  var val2 = document.getElementById("maps_id").value;  
  if(typeof(val2) == 'undefined' || val2 == null){
        val2 = '';
    }
  $.ajax({
  type: "POST",
  url: "get_uom_value.php",
  data:'maps_uom_id='+val1+'&maps_id='+val2,
  success: function(data){
    $("#displayUOMvalueForm").html(data);
  }
  });
  
}
getUOMvalue1();
hideRowUOM();
function showChildCat(){
    var elemxxx = document.querySelector('#hiddenCatInput');
elemxxx.style.display = 'block';


}

function showSubmitGroup(){
    var elemxxx1 = document.querySelector('#hiddenSubmitGroup');
elemxxx1.style.display = 'block';


}
<?php 
if(!isset($url_client_id)){
    $url_client_id = 0;
    
}

?>

</script> 
  
<script>
    $(document).ready(function() {
        $('#dataTables-bidwiz').DataTable({
            responsive: true,
            "order": [[ 0, "desc" ]],
            dom: 'Bfrtip',
        buttons: [
            'copyHtml5',
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
        });
    });
    </script>
    <script>
    $(document).ready(function() {
        $('#dataTables-bidwizlist<?php 
                            echo $random_num;
                            ?>').DataTable({
            responsive: true,
            "order": [[ 0, "desc" ]],
            dom: 'Bfrtip',
        buttons: [
            
        ]
        });
    });
    </script>
    <script>
    $(document).ready(function() {
        $('#dataTables-bidwizzz').DataTable({
            responsive: true,
            "ordering": false,
            dom: 'Bfrtip',
        buttons: [
            'copyHtml5',
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
        });
       
    });
    </script>

   <script>
   
        $('#dataTables-bidwizzz1').DataTable({
            responsive: true,
            "ordering": false,
            dom: 'Bfrtip',
        buttons: [
            'copyHtml5',
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
        });
  
    </script> 


    <script>
    $(document).ready(function() {
        $('#dataTables-bidwiz2').DataTable({
            responsive: true,
           
        
        });
    });
    </script>
    <script>
    $(document).ready(function() {
        $('#dataTables-bidwiz1').DataTable({
            responsive: true,
            
            dom: 'Bfrtip',
        buttons: [
            'copyHtml5',
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
        });
    });
    </script>

    <script>
    $(document).ready(function() {
        $('#dataTables-signup').DataTable({
            responsive: true,
            "order": [[ 0, "desc" ]],
            dom: 'Bfrtip',
        buttons: [
            'copyHtml5',
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
        });
    });
    </script>

         
 
   

<!-- priceCat-->
<script type="text/javascript">
function fetchClientItemCatDataInvoice(d){

    var a = document.getElementById(d);
    if(typeof(a) != 'undefined' || a != null){
    a.onclick = function() {
/*         var tabsx= new Tabby('[data-tabsx]');
 */
 /*
 function getSecondPart(str) {
    return str.split('-')[1];
}
// use the function:
alert(getSecondPart("sometext-20202"));


  */

  /*
  str = 'MyLongString:StringIWant;'

var mySubString = str.substring(
    str.lastIndexOf(":") + 1,
    str.lastIndexOf(";")
);

alert(mySubString);
  catid_2-2
   */
       /*  tabsx.destroy(); */



/* continue here */
        var client_id = d.split('-')[1];
        var str = d;
        var cat = str.substring(
            str.lastIndexOf("_") + 1,
            str.lastIndexOf("-")
        );

        var n = cat;
        n1 = "ncew" +n+n+client_id;
        n2 = "ocld" +n+n+client_id;
        /* check here */
        no1 = "ncew" +n+n;
        no2 = "ocld" +n+n;

        if(typeof(n) != 'undefined' || n != null){

        $.ajax({
        type: "POST",
        url: "cat_item_list_adata_item.php",
        data:'cat_id='+n+ '&cl_id='+client_id + '&clr_id=<?php echo $url_client_id1; ?>&invoice_no=<?php echo $invoice_no; ?>&in_no=<?php echo $invoice_id; ?>&state=<?php echo $state; ?>',
        success: function(data){
            $("#"+n1).html(data);
            $("#"+n2).hide();

        $('#dataTables-bidwiz'+no1).DataTable({
            responsive: true,

        });
         /* do here */

        /* '[data-tabsx]' */
        /* var qwe = '[data-tabsx'+ n + ']';
		var tabsx= new Tabby(qwe);   */


        $('#dataTables-bidwiz'+no2).DataTable({
            responsive: true,
            "order": [[ 0, "desc" ]],
            dom: 'Bfrtip',
        buttons: [
            'copyHtml5',
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
        });

        }
        });
    }

          return true;
    }
}
}
</script>

 <?php


    echo "<script>";
    $s = 1;

        $client_id = $url_client_id;
        $s = $s + 1;
        $fetch_cater = "SELECT * FROM category WHERE cat_is_delete IS NULL AND cat_approved =1";
        $run_fetch_cater = mysqli_query($conn, $fetch_cater);

        if(mysqli_num_rows($run_fetch_cater)>0){
            $k = 1;
            while($row_fetch_cater = mysqli_fetch_array($run_fetch_cater)){
                $cater_id = $row_fetch_cater['cat_id'];
                $k = $k + 1;
                $query_cater_search = "SELECT * FROM maps WHERE client_id = $client_id AND cat_id = $cater_id AND maps_approved = 1 AND maps_is_delete IS NULL";

                $run_cater_search = mysqli_query($conn, $query_cater_search);

                if(mysqli_num_rows($run_cater_search)>0){

                    $c = 'var zx'.$s.$k;

                    echo $c . ' = "catid_'. $cater_id .'-'.$client_id .'";';


                    echo 'fetchClientItemCatDataInvoice(zx' .$s. $k.');';
                }
            }
        }

   echo "</script>";


?>

<!-- /  pricecat1 -->

<!-- add item -->
<script type="text/javascript">
function addItemIN(d){
    var a = document.getElementById(d);
    if(typeof(a) != 'undefined' || a != null){
        a.onclick = function() {
            var maps = d.split('-')[1];

            var n = maps;

            if(typeof(n) != 'undefined' || n != null){
                var linker = "add-" + n;
                var linker2 = "rem-" + n;

                $.ajax({
                    type: "POST",
                    url: "in_add_item_adata.php",
                    data:'maps='+n+ '&cl_id=<?php echo $url_client_id1;?>&in_no=<?php echo $invoice_id;?>&invoice_no=<?php echo $invoice_no;?>&state=<?php echo $state;?>',
                    success: function(data){
                        $("#" +linker2).removeClass('hidden');
                        $("#" +linker).addClass('hidden');
                        updateCounter();
                    }
                });

            }

            return false;
        }
    }
}
</script>
<script>
function updateButtons(){
    var Val1 = $("#wo_state_1_counter").text();

    if(typeof(Val1) != 'undefined' || Val1 != null){
        if(Val1 > 0){

            $("#wo_state_1_next").removeClass('hidden');
            $("#wo_state_1_save").removeClass('hidden');
            $("#wo_state_1_cancel").addClass('hidden');


        }else{
            $("#wo_state_1_cancel").removeClass('hidden');
            $("#wo_state_1_save").addClass('hidden');
            $("#wo_state_1_next").addClass('hidden');            

        }

    }
}
</script>
<script>
updateButtons();
function updateCounter(){
    $.ajax({
        type: "POST",
        url: "check_in_state1_count.php",
        data:'in_no=<?php echo $invoice_id;?>',
        success: function(data){
            
            var trimStr = $.trim(data);
            
            $("#wo_state_1_counter").html(trimStr); 
            updateButtons();
           
                    
        }
    });

}
</script>



 <?php


    echo "<script>";
    $s = 1;

        $client_id = $url_client_id;
        $s = $s + 1;

        $fetch_cater = "SELECT * FROM maps WHERE cat_id = $min_cat_id  AND client_id = $url_client_id AND maps_is_delete IS NULL AND maps_approved = 1";
        $run_fetch_cater = mysqli_query($conn, $fetch_cater);

        if(mysqli_num_rows($run_fetch_cater)>0){
            $k = 1;
            while($row_fetch_cater = mysqli_fetch_array($run_fetch_cater)){
                $maps_id = $row_fetch_cater['maps_id'];
                $k = $k + 1;


                    $c = 'var nmzx'.$s.$k;

                    echo $c . ' = "add-'.$maps_id .'";';


                    echo 'addItemIN(nmzx' .$s. $k.');';

            }
        }
   echo "</script>";
?>
<!-- /  add item -->

<!-- r item -->
<script type="text/javascript">
function remItemIN(d){
    var a = document.getElementById(d);
    if(typeof(a) != 'undefined' || a != null){
        a.onclick = function() {
            var maps = d.split('-')[1];

            var n = maps;


            if(typeof(n) != 'undefined' || n != null){
                var linker = "add-" + n;
                var linker2 = "rem-" + n;

                $.ajax({
                    type: "POST",
                    url: "in_rem_item_adata.php",
                    data:'maps='+n+'&cl_id=<?php echo $url_client_id1;?>&in_no=<?php echo $invoice_id;?>&invoice_no=<?php echo $invoice_no;?>&state=<?php echo $state;?>',
                    success: function(data){
                        $("#" +linker).removeClass('hidden');
                        $("#" +linker2).addClass('hidden');
                        updateCounter();
                    }
                });

            }

            return false;
        }
    }
}
</script>


 <?php


    echo "<script>";
    $s = 1;

        $client_id = $url_client_id;
        $s = $s + 1;

        $fetch_cater = "SELECT * FROM maps WHERE cat_id = $min_cat_id  AND client_id = $url_client_id AND maps_is_delete IS NULL AND maps_approved = 1";
        $run_fetch_cater = mysqli_query($conn, $fetch_cater);

        if(mysqli_num_rows($run_fetch_cater)>0){
            $k = 1;
            while($row_fetch_cater = mysqli_fetch_array($run_fetch_cater)){
                $maps_id = $row_fetch_cater['maps_id'];
                $k = $k + 1;


                    $c = 'var remx'.$s.$k;

                    echo $c . ' = "rem-'.$maps_id .'";';


                    echo 'remItemIN(remx' .$s. $k.');';

            }
        }
   echo "</script>";
?>
<!-- /  r item -->
<!-- price--> 
<script type="text/javascript">
function fetchClientItemDataInvoice(d){

    var a = document.getElementById(d);
    if(typeof(a) != 'undefined' || a != null){ 
    a.onclick = function() {
/*         var tabsx= new Tabby('[data-tabsx]');  
 */
       /*  tabsx.destroy(); */
        var n = d.substr(11);
        n1 = "nqew" +n+n;
        n2 = "oqld" +n+n;  

        if(typeof(n) != 'undefined' || n != null){   
        $.ajax({
        type: "POST",
        url: "zclient_item_list_adata_item.php",
        data:'cl_id='+n+ '&invoice_no=<?php echo $invoice_no; ?>&in_no=<?php echo $invoice_id; ?>&state=<?php echo $state; ?>&clr_id=<?php echo $url_client_id1; ?>',
        success: function(data){
            $("#"+n1).html(data);
            $("#"+n2).hide();

       
        $('#dataTables-bidwiz'+n1).DataTable({
            responsive: true,
           
        
        });
         /* do add vars here */

        /* '[data-tabsx]' */
        var qwe = '[data-tabsx'+ n + ']';
		var tabsx= new Tabby(qwe);       

       
        $('#dataTables-bidwiz'+n2).DataTable({
            responsive: true,
            "order": [[ 0, "desc" ]],
            dom: 'Bfrtip',
        buttons: [
            'copyHtml5',
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ]
        });

        }
        });
    }

          return true;
    }   
}
}
</script>

 <?php
if($url_client_id != 0){
$query = "SELECT * FROM client WHERE is_approve = 1 AND client_is_delete IS NULL AND is_list = 1 AND client_id = $url_client_id";

$run = mysqli_query($conn, $query);

if(mysqli_num_rows($run)>0){
    echo "<script>";
    $c = 1;
    while($row = mysqli_fetch_array($run)){
    $client_id = $row['client_id'];
    $s = $c + 1;
    $c = 'var c'.$s;

    echo $c . ' = "clientq_id_'. $client_id .'";';
    

    echo 'fetchClientItemDataInvoice(c' .$s. ');';

   }

}  
   echo 'var cxx0 = "clientq_id_0";';
    echo 'fetchClientItemDataInvoice(cxx0);';
  
  echo "</script>"; 

}
?> 

<!-- /  price1 -->
<?php include_once "search_footer.php" ?>
</body>
</html>