<?php
session_start();
include_once './connection_sql.php';
?>
<!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 name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <link href="style.css" rel="stylesheet" type="text/css" media="screen" />


    <title>Search Dag</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">


    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>



    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css">

 

    <script language="JavaScript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <script language="JavaScript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
    <script language="JavaScript" src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>


    <script language="JavaScript" src="js/sales_inv.js"></script> 



</head>

<body>


    <?php
    $stname = "";
    if (isset($_GET['stname'])) {
        $stname = $_GET["stname"];
    }
    ?>
    <input type="hidden" value="" id="cur" />


    <div id="filt_table" class="CSSTableGenerator container"> 
        <table id="testTable"  class="table table-bordered">
            <?php
            echo $_SESSION['rejectdag'];
            
            $sqlven = "select * from vendor where CODE = '" . trim($_SESSION['customer']) . "'";
            $resultven = $conn->query($sqlven);
            $rowven = $resultven->fetch(); 
            
            
           
 
            echo "<table id='example'  class='table table-bordered' style='font-size: 14px;'>";

            echo "<thead><tr>";
            echo "<th>#</th>";
            echo "<th>JOB NO</th>";
            echo "<th>CUSTOMER</th>";
            echo "<th>HISTORY</th>";
            echo "<th>MAKE</th>";
            echo "<th>SIZE</th>"; 
            echo "<th>WARRENTY</th>";
            echo "<th>SERIAL NO</th>"; 
            echo "<th>COST</th>";
            echo "<th>SELLING</th>";  

            echo "</tr></thead><tbody>";
            $i=1;
            
             $sql1 = "SELECT * from dag_item where (flag ='2' or flag ='5' or flag ='6' ) and cancel='0'  and invno IS NULL";  
                
             
            //  if($_SESSION['customer']!=""){
            //     $sql1 .= " and  (cuscode='".$_SESSION['customer']."' or cuscode='C/00021')";
            //  }
            
              
             if($_SESSION['company'] !="ALL"){
                $sql1 .= " and company='".$_SESSION['company']."'";
             }
             
              $sql1 .= " order by  cuscode desc"; 
              echo $sql1;
              foreach ($conn->query($sql1) as $row) { 
                   if($_SESSION['company'] !="ALL"){ 
                       $sql1 = "Select count(*) as count from dag_item  where cancel='0'  and  serialno='".$row['serialno']."' and company='".$_SESSION['company']."' group by  serialno asc";
                    }
                    
                    
                        $result_1 = $conn->query($sql1);
                        $row_1= $result_1->fetch(); 
                        
                $cuscode = $row['id']; 
               if($row['reject'] == "1"){
                    $color="red";
                }else{
                    $color="";
                }
                
               	echo "<tr bgcolor=\"$color\">                      
                <td onclick=\"custno1('$cuscode', '". $row['jobno'] ."', '". $row['serialno'] ."');\">" . $i . "</a></td>
                <td onclick=\"custno1('$cuscode', '". $row['jobno'] ."', '". $row['serialno'] ."');\">" . $row['jobno'] . "</a></td>
                <td onclick=\"custno1('$cuscode', '". $row['jobno'] ."', '". $row['serialno'] ."');\">" . $row['cusname'] . "</a></td>
                <td onclick=\"custno1('$cuscode', '". $row['jobno'] ."', '". $row['serialno'] ."');\" style=\"background-color:yellow\">" . $row_1['count'] . "</a></td>
                <td onclick=\"custno1('$cuscode', '". $row['jobno'] ."', '". $row['serialno'] ."');\">" . $row['marker'] . "</a></td>
                <td onclick=\"custno1('$cuscode', '". $row['jobno'] ."', '". $row['serialno'] ."');\">" . $row['size'] . "</a></td>
                <td onclick=\"custno1('$cuscode', '". $row['jobno'] ."', '". $row['serialno'] ."');\">" . $row['warrenty'] . "</a></td>
                <td onclick=\"custno1('$cuscode', '". $row['jobno'] ."', '". $row['serialno'] ."');\">" . $row['serialno'] . "</a></td>  
                <td onclick=\"custno1('$cuscode', '". $row['jobno'] ."', '". $row['serialno'] ."');\">" . $row['cost'] . "</a></td> 
                <td onclick=\"custno1('$cuscode', '". $row['jobno'] ."', '". $row['serialno'] ."');\">" . $row['total'] . "</a></td>  
                </tr>";
                $i =$i +1;
            }
            
           
            ?>
        </table> </div>

        <script type="text/javascript">
                $(document).ready(function() {
           var table = $('#example').DataTable( {
            lengthChange: true,
            fixedHeader: true,
            responsive: true,
            "deferRender": true, 
             "order": [[ 1, 'asc' ]], 
            lengthMenu: [[ 25, 50,100, -1 ],[ '25 rows', '50 rows', '100 rows', 'Show all' ]],

        } );

$('div.dataTables_filter input', table.table().container()).focus();
           table.buttons().container()
           .appendTo( '#example_wrapper .col-md-6:eq(0)' );
           
       } );
        </script>

</body>
</html>
