<?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='' style='background-color: #6082BF;color: white;'>";
        echo "<td style='width: 8%;'><input type='checkbox' class='allchk' value='' > &nbsp; ALL S/US</td>";
        echo "<td style='width: 13%;'><b>Code</b></td>";
        echo "<td style='width: 30%;'><b>Name</b></td>";
        echo "</tr>";
        $ctr = 0;
        while ($row2 = mysqli_fetch_array($srchresult)) {
            $modcode = $row2['custcode'];
            $modname = $row2['name'];

            echo "<tr>";
            echo "<td>";
            echo "<input type='checkbox' class='mcheck' name='check_$ctr' value='1'>";
            echo "</td>";
            echo "<td><b>$modcode</b>
                                    <input type='hidden' style='border: none' name='scust_$ctr' class='scust' value='$modcode' readonly>
                                     <input type='hidden' name='accode_$ctr' value='$row2[accode]' class='accode' >
                                    </td>";
            echo "<td><b>$modname<input type='hidden' style='border: none' class='sname' name='sname_$ctr' value='$modname' readonly></b></td>";
  echo "<input type='hidden' name='saccode_$ctr' class='saccode' value='' >";
        echo "<input type='hidden' name='ncust_$ctr' class='ncust' value=''>";
            echo "</tr>";
            $ctr++;
        }
        echo "</table>";
       
    }
    
}