<?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 Item</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/inv.js"></script>
</head>
<body>
 
 <input type="checkbox" id="chk_stock"   >  Stock Items  Only
 </br> </br>

<!--<td><div id='stat'></div></td>-->
	<table id="example" class="display" style="width:100%">
		<thead>
		       
			<tr>
				<td align="center">Item Code</td>
				<td align="center">Description</td>
				<td align="center">Brand</td>
				<td align="center">Available Qty</td> 
				<td align="center">List Price</td> 
			</tr>
		</thead>
		<tbody>
		 <?php
                    if (isset($_GET["stname"])) {
                        if ($_GET["stname"] == "un_delivered") {
                            $_SESSION["brand"] = null;
                        }
                    }
			?>
			<input type="hidden" value="" id="cur" />

			<?php
                            require_once("connectioni.php");


                            if (!isset($_GET["stname"])) {
                                $_SESSION["stname"] ="";
                                $mstname ="";
                                
                            }   else {
                                $_SESSION["stname"] =$_GET["stname"];
                                $mstname = $_GET["stname"];
                            }

                             
                            
                            if ($mstname == "un_delivered") {

                                $sql = "SELECT * from s_mas where QTYINHAND>0 order by STK_NO  ";

                                $result = mysqli_query($GLOBALS['dbinv'], $sql);

                                while ($row = mysqli_fetch_array($result)) {

                                    echo "<tr>               
                              <td onclick=\"itno_undeliver('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['STK_NO'] . "</a></td>
                              <td onclick=\"itno_undeliver('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['DESCRIPT'] . "</a></td>
                              <td onclick=\"itno_undeliver('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['BRAND_NAME'] . "</a></td>
							  <td onclick=\"itno_undeliver('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['QTYINHAND'] . "</a></td>
							  <td onclick=\"itno_undeliver('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['SELLING'] . "</a></td>";


                                    echo "</tr>";
                                }
                            }


                            if ($mstname == "claim_item") {

                                $sql = "SELECT * from s_mas where QTYINHAND>0 order by STK_NO  ";

                                $result = mysqli_query($GLOBALS['dbinv'], $sql);

                                while ($row = mysqli_fetch_array($result)) {

                                    echo "<tr>               
                              <td onclick=\"itno_claim('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['STK_NO'] . "</a></td>
                              <td onclick=\"itno_claim('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['DESCRIPT'] . "</a></td>
                              <td onclick=\"itno_claim('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['BRAND_NAME'] . "</a></td>
							  <td onclick=\"itno_claim('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['QTYINHAND'] . "</a></td> 
							  <td onclick=\"itno_claim('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['SELLING'] . "</a></td>";


                                    echo "</tr>";
                                }
                            }if ($mstname == "defective_item") {

                                $sql = "SELECT * from s_mas where QTYINHAND>0 order by STK_NO ";

                                $result = mysqli_query($GLOBALS['dbinv'], $sql);

                                while ($row = mysqli_fetch_array($result)) {

                                    echo "<tr>               
                              <td onclick=\"itno_defect('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['STK_NO'] . "</a></td>
                              <td onclick=\"itno_defect('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['DESCRIPT'] . "</a></td>
                              <td onclick=\"itno_defect('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['BRAND_NAME'] . "</a></td>
							  <td onclick=\"itno_defect('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['QTYINHAND'] . "</a></td>
							  <td onclick=\"itno_defect('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['SELLING'] . "</a></td>";


                                    echo "</tr>";
                                }
                            }if ($mstname == "weekly_order") {

                                if (isset($_SESSION["brand"]) == true) {
                                    $sql = "SELECT * from s_mas where BRAND_NAME='" . $_SESSION["brand"] . "' order by STK_NO  ";
                                } else {
                                    $sql = "SELECT * from s_mas order by STK_NO";
                                }

                                $result = mysqli_query($GLOBALS['dbinv'], $sql);

                                while ($row = mysqli_fetch_array($result)) {

                                    echo "<tr>               
                              <td onclick=\"itno_weekly('" . $row['STK_NO'] . "');\">" . $row['STK_NO'] . "</td>
                              <td onclick=\"itno_weekly('" . $row['STK_NO'] . "');\">" . $row['DESCRIPT'] . "</td>
							  <td onclick=\"itno_weekly('" . $row['STK_NO'] . "');\">" . $row['BRAND_NAME'] . "</td>
							  <td onclick=\"itno_weekly('" . $row['STK_NO'] . "');\">" . $row['QTYINHAND'] . "</td> 
							   <td onclick=\"itno_weekly('" . $row['STK_NO'] . "');\">" . $row['SELLING'] . "</td>";


                                    echo "</tr>";
                                }
                            } else if ($mstname == "quot") {

                                echo "Brand:" . $_SESSION["brand"];
 
                                if (isset($_SESSION["brand"]) == true) {
                                    $sql = "SELECT * from s_mas where BRAND_NAME='" . $_SESSION["brand"] . "' order by STK_NO  ";
                                } else {
                                    $sql = "SELECT * from s_mas order by STK_NO";
                                }

                                $result = mysqli_query($GLOBALS['dbinv'], $sql);

                                while ($row = mysqli_fetch_array($result)) {

                                    echo "<tr>               
                              <td onclick=\"itno_quot('" . $row['STK_NO'] . "');\">" . $row['STK_NO'] . "</td>
                              <td onclick=\"itno_quot('" . $row['STK_NO'] . "');\">" . $row['DESCRIPT'] . "</td>
							  <td onclick=\"itno_quot('" . $row['STK_NO'] . "');\">" . $row['BRAND_NAME'] . "</td>
							  <td onclick=\"itno_quot('" . $row['STK_NO'] . "');\">" . $row['QTYINHAND'] . "</td> 
							  <td onclick=\"itno_quot('" . $row['STK_NO'] . "');\">" . $row['SELLING'] . "</td>";
                                    echo "</tr>";
                                }
                                $department = $_SESSION["department"];
 
                            } if ($mstname == "grn_item") {

                                $sql = "SELECT * from s_mas where BRAND_NAME='" . $_SESSION["brand"] . "' order by STK_NO  ";
                                //echo $sql;
                                $result = mysqli_query($GLOBALS['dbinv'], $sql);

                                while ($row = mysqli_fetch_array($result)) {

                                    echo "<tr>               
                              <td onclick=\"itno_grn('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['STK_NO'] . "</a></td>
                              <td onclick=\"itno_grn('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['DESCRIPT'] . "</a></td>
                              <td onclick=\"itno_grn('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['BRAND_NAME'] . "</a></td>
							  <td onclick=\"itno_grn('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['QTYINHAND'] . "</a></td> 
							  <td onclick=\"itno_grn('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['SELLING'] . "</td>";


                                    echo "</tr>";
                                }
                            } else {

                                echo "Brand :" . $_SESSION["brand"];
echo "  </br>  ";
                                if (isset($_SESSION["brand"]) == true) {
                                    $sql = "SELECT * from s_mas ";
                                   
                                     $sql .= " ORDER BY STK_NO ";
                                } else {
                                    $sql = "SELECT * from s_mas order by STK_NO";
                                } 

                                $result = mysqli_query($GLOBALS['dbinv'], $sql);

                                while ($row = mysqli_fetch_array($result)) {

                                    echo "<tr>               
                              <td align=\"center\" onclick=\"itno('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['STK_NO'] . "</td>
                              <td align=\"left\" onclick=\"itno('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['DESCRIPT'] . "</td>
							  <td align=\"center\" onclick=\"itno('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['BRAND_NAME'] . "</td>
							  <td align=\"center\" onclick=\"itno('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['QTYINHAND'] . "</td>
							  <td align=\"right\" onclick=\"itno('" . $row['STK_NO'] . "', '" . $mstname . "');\">" . $row['SELLING'] . "</td>";	
                                    $department = $_SESSION["department"];

                                    
                                }

                                echo "</tr>";
                            }
                            ?>

		</tbody>
		<tfoot>
		        
			<tr>
				<th align="center">Item No</th>
				<th align="center">Description</th>
				<th align="center">Brand</th>
				<th align="center">Stock</th> 
				<th align="center">List Price</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>


 
  
  