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

$maindb     = "item";
$trandb     = "transacn";
$formname   = "Stock New";
$file       = "stock_shade.php";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

if(isset($_POST["view"])){
    $name       = $_POST["name"];
    $asdt       = $_POST["asdt"];
    $brand      = $_POST["brand"];
    $type       = $_POST["type"];
    $smode      = $_POST["smode"];
    $godown     = $_POST["godown"];

    $namecond    = "";
    $brandcond   = "";
    $typecond    = "";
    $smodecond   = "";
    $godowncond  = "";
    
    if (!empty($name)) {
        $namecond = " AND `name` LIKE '%$name%' ";
    }
    if (!empty($brand)) {
        $brandcond = " AND `brand`='$brand' ";
    }
    if (!empty($type)) {
        $typecond = " AND `type`='$type' ";
    }
    if (!empty($smode)) {
        $smodecond = " AND `salemode`='$smode' ";
    }
    if (!empty($godown)) {
        $godowncond = " AND `godown`='$godown' ";
    }

    $getitem = mysqli_query($conn, "SELECT * FROM `item` WHERE `code`!='' $namecond $brandcond GROUP BY name ORDER BY `name`")or die(mysqli_error($conn));
}


include("includes/linkshead.php");
?>
<script src="MyScript/item.js" type="text/javascript"></script>
</head>
<body>
    <div class="container">
        <div class="row">
            <?php include("includes/head_rep.php"); ?>
            <div class="col-lg-12 pad">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="col-lg-12 pad">
                        <table class="table table-condensed table-bordered">
                            <tr style="background-color: #1ABC9C;">
                                <th style="width:20%;">ITEMNAME</th>
                                <th style="width:80%;">SHADE</th>
                            </tr>
                            <?
                            while ($item = mysqli_fetch_array($getitem)) {
                                ?>
                                <tr>
                                    <td><label class="label-control"><? Echo $item[name]; ?></label></td>
                                    <td>
                                        <?
                                        $getstock = mysqli_query($conn, "SELECT SUM(actqty) as actqty, shade FROM `transacn` WHERE `itemcode`='$item[code]' 
                                                    $typecond $smodecond $godowncond AND `vouchdt`<='$asdt' GROUP BY actbatch ORDER BY shade, actbatch")or die(mysqli_error($conn));                                        
                                        while ($stock = mysqli_fetch_array($getstock)) {
                                            ?>
                                            <label class="label-control" style="color: #1ABC9C;">
                                                <? Echo $stock[shade] ?>
                                            </label>
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <?
                                        }
                                        ?>
                                    </td>
                                    <?
                                }
                                ?>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        </div>
    </div>
    
    <?php include("includes/linksfoot.php"); ?>
</body>
</html>
