<?
session_start();
$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('opendb.php');

include_once('testtot.php');
$type=$_REQUEST['type'];
  $dto1=implode("-",array_reverse(explode("-",$verdt)));
$brres=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brrow=mysqli_fetch_array($brres);
$filename ="stk_verif.xls";
$contents="No. \t Item_cd \t Item_name \t Rate \t Stock as per Ledger<br>Qty\tValue \t Stock Actually Verified \n";


if($type=='All')
    {
        $re=mysqli_query($db,"select * from stockverification where brcode='$brcode' group by itemcode ");
    }
else
{
    $re=mysqli_query($db,"select * from stockverification where gname='$type' and brcode='$brcode' group by itemcode ");
}
//print "<TR><td></td><td></td><td></td><td></td><td align='right'>Qty</td><td  align='right'>Value</td><td align='right'>Qty</td><td  align='right'>Value</td></tr>";
$i=1;
$tprice=0;
while($row=mysqli_fetch_array($re))
{
       $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.=$ledgvl."\t";           
            $answer = $row[5];
            $contents.=$answer."\n";
}
$contents.="\n";
/*
$contents.="Grand Total\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;
?>