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

$formname = "Low Stock";
$file = "lowstock.php";


$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$fseries = $_SESSION["series_" . $dbname];

$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$tdate = date('Y-m-d');
$last10day = date('Y-m-d', strtotime($tdate . ' - ' .  10 . 'days'));

// browse($tdate);
// browse($last10day);
// SELECT itemcode ,qty , abs(qty) as avgqtyforlasttendays FROM `transacn` WHERE vouchdt >= '$tdate' and vouchdt <='$last10day' and qty < 0 GROUP by itemcode
// die();
    $geticode= mysqli_query($conn, "SELECT itemcode  FROM `transacn` WHERE qty < 0 GROUP by itemcode")or die(mysqli_error($conn));
    $stk = mysqli_fetch_array($getstk);
die();

    $get = mysqli_num_rows($getstk);
    
    
    include("includes/linkshead.php");
    $mfdt = date("d-m-Y", strtotime($mfrmdate));
    $mtdt = date("d-m-Y", strtotime($mtodate));
    ?>
    <style type="text/css">
        #tabital{
            font-style: italic;
        }
        #font1{
            font-style: italic;
        }
        #boldfont{
            font-weight: bold; 
        }
    </style>

    </head>
    <body>
        <div class="container">
            <?php include("includes/head_rep.php"); ?>
            <div class="row">
                <div class="col-lg-12 pad">
                    <table style="background: white;width: 100%" class="table table-condensed table-hover">
                        <thead class="mySearchTr">
                            <tr>
                                <th style="width:5%">  Sr</th>
                                <th style="width:10%"> Item Name</th>
                                <th style="width:10%"> Low Stock On</th>
                                <th style="width:10%"> Live Stock</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $ctr = 0;
                            $mtqty = 0;
                            $mgtot = 0;
                            while ($stk = mysqli_fetch_array($getstk)){
                                $itemcode = $stk['itemcode'];
                                $sqty = $stk['sqty'];
                                $ctr++;

                                $getitemstk = mysqli_query($conn, "SELECT code, name , lowstk FROM item where code ='$itemcode' and lowstk < '$sqty' ")or die(mysqli_error($conn));
                                // print table($getitemstk);
                                // die();
                                $itemstk = mysqli_fetch_array($getitemstk);
                                Echo "<tr id='boldfont'>";
                                Echo "<td>$ctr</td>";
                                Echo "<td>$itemstk[code] - $itemstk[name]</td>";
                                Echo "<td>$itemstk[lowstk]</td>";
                                Echo "<td>$itemstk[lowstk]</td>";
                                // $mtqty = $pmain['totqty'] + $mtqty;
                                // $mgtot = $pmain['subtotal'] + $mgtot;
                                Echo "</tr>";
                                }
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <?php include("includes/linksfoot.php");
        ?>
    </body>
    </html>
