<?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 Invoice</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="js/search_joborder.js"></script> -->

    <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

           $phrase = "";
                    // if($stname == "arn"){
                    //     $phrase = " where cancel='0' ";
                    // }
                    require_once("connectioni.php");

 echo "<table id='example'  class='table table-bordered' style='font-size: 14px;'>";

           echo "<thead><tr>";
            echo "<th style=\"text-align:center\">Invoice No</th>";
            echo "<th style=\"text-align:center\">Invoice Date</th>"; 
            echo "<th style=\"text-align:center\">Customer</th>";
             echo "<th style=\"text-align:center\">Brand</th>"; 
             echo "<th style=\"text-align:center\">Po No</th>"; 
             echo "<th style=\"text-align:center\">Job No</th>";  
             echo "<th style=\"text-align:center\">Vehicle No</th>";   
             echo "<th style=\"text-align:center\">Contact No</th>";  
            echo "<th style=\"text-align:center\">Invoice Value</th>";   


            echo "</tr></thead><tbody>";
            

            if ($stname == "crn") {
                if ($_SESSION["custno"] != "") {
                    if ($_SESSION["company"]!="") {           
                         $sql = "SELECT * FROM s_salma where C_CODE='" . $_SESSION["custno"] . "' and DEV='" . $_SESSION["dev"] . "' and CANCELL='0' and  company='".$_SESSION["company"]."'  order by id desc limit 150";
                    }else{
                         $sql = "SELECT * FROM s_salma where C_CODE='" . $_SESSION["custno"] . "' and DEV='" . $_SESSION["dev"] . "' and CANCELL='0'    order by id desc  ";
                    } 
                } else {
                    if ($_SESSION["company"]!="") {           
                         $sql = "SELECT * FROM s_salma where    CANCELL='0' and  company='".$_SESSION["company"]."'  order by id desc ";
                    }else{
                         $sql = "SELECT * FROM s_salma where    CANCELL='0'    order by id desc ";
                    }  
                }
            } else if ($stname == "grn") {
                if ($_SESSION["custno"] != "") {
                    if ($_SESSION["company"]!="") {           
                         $sql = "SELECT * FROM s_salma where C_CODE='" . $_SESSION["custno"] . "' and DEV='" . $_SESSION["dev"] . "' and CANCELL='0' and  company='".$_SESSION["company"]."'  order by id desc  ";
                    }else{
                         $sql = "SELECT * FROM s_salma where C_CODE='" . $_SESSION["custno"] . "' and DEV='" . $_SESSION["dev"] . "' and CANCELL='0'    order by id desc  ";
                    }  
                } else {
                    if ($_SESSION["company"]!="") {           
                         $sql = "SELECT * FROM s_salma where   DEV='" . $_SESSION["dev"] . "' and CANCELL='0' and  company='".$_SESSION["company"]."'  order by id desc  ";
                    }else{
                         $sql = "SELECT * FROM s_salma where   DEV='" . $_SESSION["dev"] . "' and CANCELL='0'    order by id desc  ";
                    } 
                }
            } else if ($stname == "search_grn") {
                if ($_SESSION["company"]!="") {           
                     $sql = "SELECT * FROM s_crnma where CANCELL='0' and  company='".$_SESSION["company"]."'  order by id desc  ";
                }else{
                     $sql = "SELECT * FROM s_crnma where CANCELL='0'    order by id desc  ";
                }  
            } else {
                 if ($_SESSION["company"]!="") {           
                     $sql = "SELECT * FROM s_salma where DEV='" . $_SESSION["dev"] . "' and  company='".$_SESSION["company"]."'  order by id desc  ";
                }else{
                     $sql = "SELECT * FROM s_salma where DEV='" . $_SESSION["dev"] . "'    order by id desc  ";
                }   
            }
                    // echo $sql;
            $result = mysqli_query($GLOBALS['dbinv'], $sql);

                    

           
$color="";
            foreach ($conn->query($sql) as $row) { 
              $cuscode = $row["REFNO"];
 if($row['CANCELL'] == "1"){
                    $color="red";
                }else{
                    $color="";
                }
                
               	echo "<tr bgcolor=\"$color\">                           
                <td onclick=\"invno_inv('" . $row['REF_NO'] . "', '" . $stname . "');\">" . $row['REF_NO'] . "</a></td>
                <td align=\"center\" onclick=\"invno_inv('" . $row['REF_NO'] . "', '" . $stname . "');\">" . $row['SDATE'] . "</a></td> 
                <td onclick=\"invno_inv('" . $row['REF_NO'] . "', '" . $stname . "');\">" . $row["CUS_NAME"] . "</a></td>
                <td onclick=\"invno_inv('" . $row['REF_NO'] . "', '" . $stname . "');\">" . $row["Brand"] . "</a></td>
                <td onclick=\"invno_inv('" . $row['REF_NO'] . "', '" . $stname . "');\">" . $row["ORD_NO"] . "</a></td>
                <td onclick=\"invno_inv('" . $row['REF_NO'] . "', '" . $stname . "');\">" . $row["jobno"] . "</a></td>
                <td onclick=\"invno_inv('" . $row['REF_NO'] . "', '" . $stname . "');\">" . $row["veheno"] . "</a></td> 
                <td onclick=\"invno_inv('" . $row['REF_NO'] . "', '" . $stname . "');\">" . $row["TEL"] . "</a></td> 
                <td align=\"right\" onclick=\"invno_inv('" . $row['REF_NO'] . "', '" . $stname . "');\">" . $row['GRAND_TOT'] . "</a></td>
                </tr>";
            }
            ?>
        </table> </div>

      <script type="text/javascript">
                $(document).ready(function() {
           var table = $('#example').DataTable( {
            lengthChange: true,
            fixedHeader: true,
            responsive: true,
            "deferRender": true, 
             "order": [[ 3, 'desc' ]], 
            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>



 