<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include("includes/function.php");

$zdb = $_SESSION["zdbyear_$dbname"];
$ztit = $_SESSION["tit"];
$usertype = $_SESSION["usertype"]; 
$user = $_SESSION['username_' . $dbname];
$keyfld = "vouchno";

mysqli_select_db($conn, $zdb);

if (isset($_REQUEST["search"])) {
    $searchTerm = $_REQUEST["search"];


//    $getitemcode = mysqli_query($conn, "select `code`,`name` from item where `name` = '$searchTerm'") or die(mysqli_error($conn));
//    $itemc = mysqli_fetch_array($getitemcode);
//    $itemcode = $itemc[code];
//    browse($itemcode);
    $cond = "AND `custcode` like '%$searchTerm%'";

    $mctr = 0;
    $srchresult = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode` != '' AND `grpcode`='010' $cond ")or die(mysqli_error($conn));
    


                    if (mysqli_num_rows($srchresult) > 0) {
                        echo "<table class='table table-bordered table-hover myTable'>";
                        echo "<tr class='clickable-row' style='background-color: #6082BF;color: white;'>";
                        echo "<td><b>Code</b></td>";
                        echo "<td><b>Name</b></td>";
                        echo "<td><b>Address</b></td>";
                        echo "</tr>";
                        $sctr = 0;
                        $ctr = 0;
                        while ($row2 = mysqli_fetch_array($srchresult)) {
                            $modcode = $row2['custcode'];
                            $modname = $row2['name'];
                            $add1 = $row2[add1];
                            $add2 = $row2[add2];
                            $add3 = $row2[add3];
                            

                            echo "<tr class='schltab'>";
                            echo "<td><b>$modcode</b>
                                <input type='hidden' style='border: none' class='scust' value='$modcode' readonly>
                                            <input type='hidden' value='$row2[medmcode]' class='medium'>
                                            <input type='hidden' value='$row2[accode]' class='accode'>
                                    </td>";
                            echo "<td><b>$modname</b>
                                    <input type='hidden' style='border: none' class='sname' value='$modname' readonly></td>";
                            echo "<td><b>$add1 $add2 $add3
                                     <input type='hidden' style='border: none' class='sadd1' value='$add1' readonly><br>
                                     <input type='hidden' style='border: none' class='sadd2' value='$add2' readonly><br>          
                                     <input type='hidden' style='border: none' class='sadd3' value='$add3' readonly>          
                                   </b></td>";
                            echo "</tr>";
                            $sctr++;
                            $ctr++;
                        }
                        echo "</table>";
                    }
}