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

$zdb = $_SESSION["zdbyear_$dbname"];
$ztit = $_SESSION["tit"];
mysqli_select_db($conn, $zdb);

if ($_REQUEST["code"]) {
    $code = $_REQUEST["code"];
    $getinv = mysqli_query($conn, "SELECT * FROM `engfixacc` WHERE code = '$code' ORDER BY srno") or die(mysqli_error($conn));
    
    $ctr = 0;
    $zctr = 0;
    while ($row = mysqli_fetch_array($getinv)) {
      $zctr++;  
      $getitem = mysqli_query($conn, "SELECT `name` FROM `item` WHERE code='$row[item]'")or die(mysqli_error($conn));
      $mitem = mysqli_fetch_array($getitem);
      
        echo "<tr>";
        echo "<td align='left'><input type='text' name='srno_$ctr' class='sno form-control' value='$row[srno]'/></td>";

        echo "<td align='left'>";
        echo "<input list='item_$ctr2' name='item_$ctr2' class='item form-control'  value='$gitem[name]' style='height:33px;'>";
        echo "<datalist id='item_$ctr2'>";
        echo "<option value='$gitem->name'>";
        $mitem = mysqli_query($conn, "SELECT `name` FROM `item` ORDER BY `name`") or die(mysqli_error($conn));
        while ($trow1 = mysqli_fetch_array($mitem)) {
            echo "<option value='$trow1[name]'>";
        }
        echo "</datalist>";
        echo "</td>";
        echo "<td align='center'><input type='text' name='qty_$ctr' style='text-align:right' class='qty form-control' value='$row[qty]'/></td>";
        echo "<td align='left'>";
        echo "<input type='text' size='6'  name='unit_$ctr`' class='unit form-control'  value='$row[unit]'/>";
        echo "</td>";
        echo "</tr>";
        $ctr++;
    }?>
        <input type="hidden" id="items" name="items" value="<?php echo $ctr; ?>"/>  
        <?php
} else {
    echo "ERROR";
}
?>
