<?php

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

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


$prodname = $_REQUEST["prodname"];
$barcode = $_REQUEST["barcode"];
$size = $_REQUEST["size"];
$quality = $_REQUEST["quality"];
$brand = $_REQUEST["brand"];
$todt = $_REQUEST["todt"];
$frmdt = $_REQUEST["frmdt"];
$godown = $_REQUEST["godown"];

if (!empty($godown)) {
    $godowncond = "and godown = '$godown'";
}
if (!empty($prodname)) {
    $prodnamecond = "and prodname = '$prodname'";
}

if (!empty($barcode)) {
    $barcodecond = "and prodcode = '$barcode'";
}
if (!empty($size)) {
    $sizecond = "and size = '$size'";
}
if (!empty($brand)) {
    $brandcond = "and brand = '$brand'";
}
if (!empty($quality)) {
    $qualitycond = "and quality = '$quality'";
}

//$mown1 = mysqli_query($conn, "SELECT * FROM `item` where code != '' $namecond") or die(mysqli_error($conn));
$getitem = mysqli_query($conn, "SELECT * FROM `transacn` WHERE  `vouchdt` >= '$frmdt' AND `vouchdt` <= '$todt'
                                $brandcond $prodnamecond $godowncond $qualitycond $sizecond $barcodecond  group by prodcode order by prodname") or die(mysqli_error($conn));

while ($row = mysqli_fetch_array($getitem)) {
    $getitem1 = mysqli_query($conn, "SELECT * FROM `item` WHERE `code`='$row[prodcode]' ")or die(mysqli_error($conn));
    $fitem = mysqli_fetch_array($getitem1);
    echo "<tr>";
    echo "<td class='text-center'><input type='checkbox' name='check[]' class='chk' style='height:20px;width:25px'  value='$row[prodcode]' checked></td>";
    echo "<td tabindex='-1'>$fitem[prodname]<input type='hidden' name='code_$ctr' value='$row[prodcode]' readonly tabindex='-1'></td>";
    echo "<td tabindex='-1'>$fitem[size]</td>";
    echo "<td tabindex='-1'>$fitem[brand]</td>";
    echo "<td tabindex='-1'>$fitem[quality]</td>";
    echo "<td tabindex='-1'>$fitem[code]</td>";
    echo "</tr>";
}
?>
