<?php
include("includes/check_auth_user.php");
include("includes/dbconnect.php");
include('includes/function.php');
$zdb = $_SESSION["zdbyear_$dbname"];
mysqli_select_db($conn, $zdb);
$maindb = "transacn";
$bdb = "accmast";
if (isset($_REQUEST["item"])) {
    $item = $_REQUEST["item"];
//    $location = $_REQUEST["location"];
//    $vouchdt = $_REQUEST["vouchdt"];
//    
    $getiname = mysqli_query($conn, "SELECT * FROM `item` WHERE `name` = '$item' ")or die(mysqli_error($conn));
    $itemcode = mysqli_fetch_object($getiname);

//    $getilocation = mysqli_query($conn, "SELECT * FROM `location` ")or die(mysqli_error($conn));
//    $loccode = mysqli_fetch_object($getilocation);
//    
    $getdata = mysqli_query($conn, "SELECT SUM(qty) AS tqty, location FROM `transacn` WHERE itemcode = '$itemcode->code'
                            group by location order by location")or die(mysqli_error($conn));
    ?>

    <?php echo "<font color='#428BCA' style='float:left;margin-left:10px;'><b>$item</b></font>"; ?>
    <table border="1" width="100%" class="table table-bordered">
        <tr>
            <th align='left'>Location</th>        
            <th style="text-align:right">Qty.</th>        
        </tr> 
        <?php
        while ($row = mysqli_fetch_object($getdata)) {
            $getloc = mysqli_query($conn, "SELECT * FROM `location` WHERE `code` = '$row->location'") or die(mysqli_error($conn));
            $loc = mysqli_fetch_object($getloc);
            echo "<tr class='record_select' id='$loc->name' rel='$row->tqty' style='cursor:pointer;'>";
//                    echo "<tr>";
            echo "<td align='left'>";
            echo $loc->name;
            echo "</td>";
            echo "<td align='right'>";
            echo $row->tqty;
            echo "</td>";
            echo "</tr>";
        }
        ?>  
    </table>
    <?php
}
?>