<?php
session_start();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Search Orders</title> 
	<style type="text/css">
		tfoot input {
			width: 100%;
			padding: 3px;
			box-sizing: border-box;
		}
	</style>
	<link  href="new/vendor/new/multi/jquery.dataTables.min.css" rel="stylesheet" type="text/css"> 
	<script src="new/vendor/new/multi/jquery-3.5.1.js" ></script>
	<script src="new/vendor/new/multi/jquery.dataTables.min.js" ></script>
<script language="JavaScript" src="js/ord.js"></script>
  <script>
     $(document).ready(function () {
        var table = $('#example').DataTable();    
        
        
        // $('#Option4').click(function () {
        //     if ($(this).is(':checked')) { 
        //         $.fn.dataTable.ext.search.pop(); 
        //     }
        //     table.draw();
        // });
         $('#Option4').click(function () { 

            $.fn.dataTable.ext.search.pop();
            $.fn.dataTable.ext.search.push(
                function (settings, data, dataIndex) {
                    return data[8] != '0';
                }
                ); 
            table.draw();
        }); 
         
        $('#Option1').click(function () { 

            $.fn.dataTable.ext.search.pop();
            $.fn.dataTable.ext.search.push(
                function (settings, data, dataIndex) {  
                    return data[8] == '0';
                }
                ); 
            table.draw();
        }); 
         
        
         $('#Option5').click(function () { 

            $.fn.dataTable.ext.search.pop();
            $.fn.dataTable.ext.search.push(
                function (settings, data, dataIndex) {
                    return data[4] == 'OK';
                       
                }
                
                 
            table.draw();
        }); 
    });
</script>

</head>
<body>
 
 
 	<tr>
		<td  background="" ><input type="radio" name="radio" id="Option5" value="Option5"  onclick="update_list('$stname');" />
		Approved Orders&nbsp;&nbsp;</td>

		<td  background="" ><input type="radio" name="radio" id="Option1"  value="Option1"  onclick="update_list('$stname');" />
		Non Approved Orders&nbsp; &nbsp;</td>
		<td background="" ><input type="radio" name="radio" id="Option2" value="Option2" onclick="update_list('$stname');"/>
		To SM&nbsp; &nbsp;</td>
		<td  background="" ><input type="radio" name="radio" id="Option3" value="Option3" onclick="update_list('$stname');"/>
		To MD&nbsp; &nbsp;</td>
		<td  background="" ><input type="radio" name="radio" id="Option4"  checked="checked" value="Option4" onclick="update_list('$stname');"/>
		Approved & Invoiced</td>
		</tr>
		</br>
		</table>
		<table width="810" border="0" class=\"form-matrix-table\">
		<tr>
	</br>
<!--<td><div id='stat'></div></td>-->
	<table id="example" class="display" style="width:100%">
		<thead>
		       
		<tr>
			                  <td align="center">SO No</td>
                              <td align="center">Customer</td>
                              <td align="center">SO Date</td> 
                              <td align="center">Invoice Total</td>
                              <td align="center">Status</td> 
                              <td align="center">Sales Executive</td> 
                              <td align="center">Approved By</td> 
                              <td align="center">Approved Level</td> 
                              <td align="center">Invoice No</td> 
                               
			</tr>
		</thead>
		<tbody>
		 
                 	<?php
		$stname = $_GET["stname"];
		$_SESSION["stname"] = $stname;
		?>
		 
			<input type="hidden" value="" id="cur" />

			<?php
                            require_once("connectioni.php");
  
                            if ($_SESSION["company"]!="") {           
                                 $sql = "SELECT REF_NO,CUS_NAME,SDATE,GRAND_TOT,Result,SAL_EX,approveby,Forward,INVNO FROM s_cusordmas where   CANCELL='0' and  company='".$_SESSION["company"]."'  order by id asc ";
                            }else{
                                 $sql = "SELECT REF_NO,CUS_NAME,SDATE,GRAND_TOT,Result,SAL_EX,approveby,Forward,INVNO FROM s_cusordmas where   CANCELL='0'  order by id asc "; 
                                 
                            }  
                            
                            
                            
                                $result = mysqli_query($GLOBALS['dbinv'], $sql);
                                while ($row = mysqli_fetch_array($result)) {
                                $sql1 = "SELECT * FROM s_salrep where REPCODE = '" . $row["SAL_EX"] . "'";
                                $result1 = mysqli_query($GLOBALS['dbinv'], $sql1);
                                $row1 = mysqli_fetch_array($result1);
                                    echo "<tr>
                <td align=\"center\" onclick=\"invno('" . $row['REF_NO'] . "','" . $stname . "');\">" . $row['REF_NO'] . "</a></td>
                <td align=\"left\" onclick=\"invno('" . $row['REF_NO'] . "','" . $stname . "');\">" . $row['CUS_NAME'] . "</a></td>
                <td align=\"center\" onclick=\"invno('" . $row['REF_NO'] . "','" . $stname . "');\">" . $row['SDATE'] . "</a></td> 
                <td align=\"center\" onclick=\"invno('" . $row['REF_NO'] . "','" . $stname . "');\">" . $row['GRAND_TOT'] . "</a></td> 
                <td align=\"center\" onclick=\"invno('" . $row['REF_NO'] . "','" . $stname . "');\">" . $row['Result'] . "</a></td> 
                 <td align=\"center\" onclick=\"invno('" . $row['REF_NO'] . "','" . $stname . "');\">" . $row1['Name'] . "</a></td> 
                 <td align=\"center\" onclick=\"invno('" . $row['REF_NO'] . "','" . $stname . "');\">" . $row['approveby'] . "</a></td> 
                 <td align=\"center\" onclick=\"invno('" . $row['REF_NO'] . "','" . $stname . "');\">" . $row['Forward'] . "</a></td> 
                 <td align=\"center\" onclick=\"invno('" . $row['REF_NO'] . "','" . $stname . "');\">" . $row['INVNO'] . "</a></td> 
                </tr>";
							}
                                echo "</tr>";
                           
                            ?>

		</tbody>
		<tfoot>
		        
			<tr>
	                    	 <th align="center">SO No</th>
                              <th align="center">Customer</th>
                              <th align="center">SO Date</th> 
                              <th align="center">Invoice Total</th>
                              <th align="center">Status</th> 
                              <th align="center">Sales Executive</th> 
                              <th align="center">Approved By</th> 
                              <th align="center">Approved Level</th>
                              <th align="center">Invoice No</th> 
			</tr>
		</tfoot>
	</table>

</body>
</html>
<script type="text/javascript">
	$(document).ready(function() {
    // Setup - add a text input to each footer cell
    $('#example tfoot th').each( function () {
    	var title = $(this).text();
    	$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
    } );
    
$('#chk_stock').on('change', function() {
  if ($(this).is(':checked')) {
    $.fn.dataTable.ext.search.push(
      function(settings, data, dataIndex) {  
         return data[3] > 0
      }
    )
  } else {
    $.fn.dataTable.ext.search.pop()
  }
  table.draw()
})

    // DataTable
    var table = $('#example').DataTable({
    	
    	lengthChange: true,
    	fixedHeader: true,
    	responsive: true,
    	"deferRender": true,
    	"order": [[ 0, 'desc' ]],
    	lengthMenu: [[ 10, 25, 50,100, -1 ],[ '10 rows', '25 rows', '50 rows', '100 rows', 'Show all' ]],
    	initComplete: function () {
            // Apply the search
            this.api().columns().every( function () {
            	var that = this;

            	$( 'input', this.footer() ).on( 'keyup change clear', function () {
            		if ( that.search() !== this.value ) {
            			that
            			.search( this.value )
            			.draw();
            		}
            	} );
            } );
        }
    });

} );
</script>


 
  
  