<?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 Customer</title>
    <style type="text/css">
        tfoot input {
            width: 100%;
            padding: 3px;
            box-sizing: border-box;
        }
    </style>
     <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.22/css/jquery.dataTables.min.css">
    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>  
 
   
    <script language="JavaScript" src="js/inv.js"></script>
</head>
<body>

           <?php

$vendorType = "";
                if ($stname == "supplier") {
                    $vendorType = "Supplier";

                } else if ($stname == "sup_mast") {
                   $vendorType = "Supplier";
                } else {
                    $vendorType = "Customer";
                }
                ?>

    <table id="example" class="display" style="width:100%">
        <thead>
            <tr>
                <th>Code</th>
                <th>Name</th>
                <th>Address</th>
                <th>Tel</th>
            </tr>
        </thead>
        <tbody>
            <?php
            $stname = "";
            if (isset($_GET['stname'])) {
                $stname = $_GET["stname"];
            }
            ?>
            <input type="hidden" value="" id="cur" />

            <?php
            require_once("config.inc.php");
                require_once("DBConnector1.php");
                $db = new DBConnector();

                if ($_GET["stname"] == "incentive2") {
                    $sql = "SELECT * from vendor where CAT='Z' order by CODE  ";
                } else if ($_GET["stname"] == "incentive") {
                    $sql = "SELECT * from vendor where CAT<>'X' and CAT<>'Z' order by CODE  ";
                } else if ($_GET["stname"] == "supplier") {
                    $sql = "select DISTINCT sup_code,SUP_NAME from s_purmas";
                }else if($_GET["stname"] == "sup_mast"){
                     $sql = "SELECT * from vendor where vendorType = 'S' or CAT='B'   ";
                }else if($_GET["stname"] == "cust_mast"){
                     $sql = "SELECT * from vendor where vendorType = 'C' or CAT='B'  ";
                }else if($_GET["stname"] == "setInvoice"){
                    $sql = "SELECT * from vendor where CAT<>'Z' and acno!='1' and blacklist != '1' order by CODE  ";
                }else {
                    $sql = "SELECT * from vendor where CAT<>'Z' and acno!='1' order by CODE  ";
                }
                $stname = $_GET["stname"];
  
                $result = $db->RunQuery($sql);
                if ($stname != "supplier") {
                    while ($row = mysqli_fetch_array($result)) {
                        $cuscode = $row["CODE"];
                        echo "<tr>               
                              <td onclick=\"custno('$cuscode', '$stname');\">" . $row['CODE'] . "</a></td>
                              <td onclick=\"custno('$cuscode', '$stname');\">" . $row['NAME'] . "</a></td>
                         		<td onclick=\"custno('$cuscode', '$stname');\">" . $row['ADD1'] . "</a></td>
                         		<td onclick=\"custno('$cuscode', '$stname');\">" . $row['TELE1'] . "</a></td>
                              
                            </tr>";
                    }
                } else {
                    while ($row = mysqli_fetch_array($result)) {
                        $cuscode = $row["sup_code"];
                        echo "<tr>               
                              <td onclick=\"custno('$cuscode', '$stname');\">" . $row['sup_code'] . "</a></td>
                              <td onclick=\"custno('$cuscode', '$stname');\">" . $row['SUP_NAME'] . "</a></td>
                              <td onclick=\"custno('$cuscode', '$stname');\"></a></td>
                            </tr>";
                    }
                }
            ?>

        </tbody>
        <tfoot>
            <tr>
                <th>Crn No</th>
                <th>Customer</th>
                <th>Date</th>
                <th>Amount</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+'" />' );
    } );

    // 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>


