<?
session_start();
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
include_once('testtot.php');
$verdt=$_REQUEST['dfrom'];


$type=$_REQUEST['gname'];

$brres=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brrow=mysqli_fetch_array($brres);
if($type=='All')
    {
        $re=mysqli_query($db,"select * from stockverification where stockverifydt='$verdt' and brcode='$brcode' group by itemcode ");
    }
else
{
    $re=mysqli_query($db,"select * from stockverification where stockverifydt='$verdt' and gname='$type' and brcode='$brcode' group by itemcode ");
}
$filename ="stkrpt_ver.xls";
$contents="       \t          \t           \t Item Group : \t\t\t $type \t\t\t\t\t\n";
$contents.="No. \t Stock No.\t Item Name \t Rate \t Stock as per Ledger \t  \t Stock actually verified \t\t Excess \t \t Short \t \t Remarks \n";
$contents.=" \t \t  \t  \t Qty \t Value  \t Qty \t Value \t Qty \t Value \t Qty \t Value  \n";

$i=1;
$tprice=0;
while($row=mysqli_fetch_array($re))
{
       if(($row[4]==0)&&($row[5]==0))
       {    $a=0;
       }
       else
       {
       $op_qty = $row[2]-$row[3];
       $ledgvl=$row[3]*$row[4];
       $actualvl=$row[3]*$row[5];
       $excsvl=$row[3]*$row[10];
       $shrtvl=$row[3]*$row[9];




            $contents.=$i++."\t";
            $contents.=$row[1]."\t";
            $contents.=$row[2]."\t";
            $contents.=$row[3]."\t";
            $contents.=$row[4]."\t";
            $contents.=number_format($ledgvl,2)."\t";
            $contents.=$row[5]."\t";
            $contents.=number_format($actualvl,2)."\t";
            $contents.=$row[10]."\t";
            $contents.=$excsvl."\t";
            $contents.=$row[9]."\t";
            $contents.=$shrtvl."\t";
            $contents.=$row[13]."\n";

        }

}
$contents.="\n";
$contents.="Grand Total\t";
$contents.="\t";
$contents.="\t";
$contents.="\t";

$contents.="\t";
$contents.="\t";
$contents.="\t";
$contents.="\t";
$contents.="\t";
$contents.="\t";
$contents.="\t";
$contents.="\t";
$contents.="\t";
$contents.="\t";
$contents.=number_format($tprice,2)."\t";
$contents = strip_tags($contents);
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
print $contents;
?>