<?
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'];
      $y1=$_REQUEST['y1'];
      $m1=$_REQUEST['m1'];
      $d1=$_REQUEST['d1'];
      $y2=$_REQUEST['y2'];
      $m2=$_REQUEST['m2'];
      $d2=$_REQUEST['d2'];
      $type=$_REQUEST['type'];

 //$dfrom=$y1.'-'.$m1.'-'.$d1;
 //$dto=$y2.'-'.$m2.'-'.$d2;
  $dto1=implode("-",array_reverse(explode("-",$verdt)));
$brres=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brrow=mysqli_fetch_array($brres);
?>
<script type="text/javascript" src="number_to_word.js"></script>
<body bgcolor="#0033FF">


<?php //include('includes/top.php'); ?>
<center>
<br>
<table>
<TR><TD COLSPAN=2 ALIGN=CENTER><b> KERALA KHADI & VILLAGE INDUSTRIES BOARD  </b></font><BR>
 <b><? echo $brrow[1] ?>
</font>
</td></tr>
</TABLE>
<font> <? print "<B>STOCK VERIFICATION STATEMENT AS ON ".$dto1."</B>";?></font>
<link rel="stylesheet" href="style.css" type="text/css" />
<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form.css" rel="stylesheet" />

<style type="text/css">
tr.top td { border-top: thin solid black; }
tr.bottom td { border-bottom: thin solid black; }
tr.row td:first-child { border-left: thin solid black; }
tr.row td:last-child { border-right: thin solid black; }
</style>
<center>
<font> <? print "<B><I>ABSTRACT</B></I>";?></font>
<?
$i=1;
$tprice=0;
$mctr=1;
$mctr_1=1;
$pageno = 1;
$re=mysqli_query($db,"select gname,sum(ledqty*sellprice),sum(curstk*sellprice),sum(stock_short*sellprice),sum(stock_excess*sellprice),count(itemcode) from stockverification where stockverifydt='$verdt' and brcode='$brcode' group by gname");
print "<table  cellspacing=1 cellpadding=3 bgcolor='lightsteelblue' style='border-collapse: collapse;' class='report'>";
//print "<tr><th>Item </td><td>Stock as per Ledger</td><td>Stock actually verified</td><td align='center'>Excess</td><td align='center'>Short</td><td>Remarks</td></TR>";
print "<tr><th>Item <th>Stock as per Ledger<th>Stock actually verified<th>Excess<th>Short<th>Remarks</TR>";
$i=1;
$tot_led = 0;
$tot_act = 0;
$tot_exc = 0;
$tot_sho = 0;
$ctr_khadi = 1;
$ctr_vip = 1;
$mstr_vip[]="";
$mstr_khadi[]="";
$mkhadi_tot_1 = 0;
$mkhadi_tot_2 = 0;
$mkhadi_tot_3 = 0;
$mkhadi_tot_4 = 0;
$mvip_tot_1 = 0;
$mvip_tot_2 = 0;
$mvip_tot_3 = 0;
$mvip_tot_4 = 0;
while($row=mysqli_fetch_array($re))
{
       $mtot_pages = ceil($row[5]/25);
       if(strpos($row[0], "VIP")>0)
       {
          $mstr_vip[$ctr_vip] ="\n<tr bgcolor=white onMouseOver=bgColor='silver'; onMouseOut=bgColor='white' style='border:1px solid black;'>";
          $mstr_vip[$ctr_vip] .="<td >$row[0]($mtot_pages PAGES)</td><td align=right>".number_format($row[1],2)."</td><td align=right >".number_format($row[2],2)."</td><td align=right>".number_format($row[4],2)."</td><td align=right>".number_format($row[3],2)."</td><td></td></tr>";
          $ctr_vip++;
          $mvip_tot_1 += $row[1];
          $mvip_tot_2 += $row[2];
          $mvip_tot_3 += $row[4];
          $mvip_tot_4 += $row[3];
       }
       else
       {
          $mstr_khadi[$ctr_khadi] ="\n<tr bgcolor=white onMouseOver=bgColor='silver'; onMouseOut=bgColor='white' style='border:1px solid black;'>";
          $mstr_khadi[$ctr_khadi] .="<td >$row[0]($mtot_pages PAGES)</td><td align=right>".number_format($row[1],2)."</td><td align=right >".number_format($row[2],2)."</td><td align=right>".number_format($row[4],2)."</td><td align=right>".number_format($row[3],2)."</td><td></td></tr>";
          $ctr_khadi++;
          $mkhadi_tot_1 += $row[1];
          $mkhadi_tot_2 += $row[2];
          $mkhadi_tot_3 += $row[4];
          $mkhadi_tot_4 += $row[3];

       }
       $tot_led += $row[1];
       $tot_act += $row[2];
       $tot_exc += $row[4];
       $tot_sho += $row[3];
}

for ($ctr=1;$ctr<$ctr_khadi;$ctr++)
{
      print $mstr_khadi[$ctr];
}
print "\n<tr bgcolor=white onMouseOver=bgColor='silver'; onMouseOut=bgColor='white' style='border:1px solid black;'>";
print "<td ><b>KHADI TOTAL</td><td align=right><b>".number_format($mkhadi_tot_1,2)."</td><td align=right ><b>".number_format($mkhadi_tot_2,2)."</td><td align=right><b>".number_format($mkhadi_tot_3,2)."</td><td align=right><b>".number_format($mkhadi_tot_4,2)."</td><td></td></tr>";

for ($ctr=1;$ctr<$ctr_vip;$ctr++)
{
      print $mstr_vip[$ctr];
}
print "\n<tr bgcolor=white onMouseOver=bgColor='silver'; onMouseOut=bgColor='white' style='border:1px solid black;'>";
print "<td ><b>VIP TOTAL</td><td align=right><b>".number_format($mvip_tot_1,2)."</td><td align=right ><b>".number_format($mvip_tot_2,2)."</td><td align=right><b>".number_format($mvip_tot_3,2)."</td><td align=right><b>".number_format($mvip_tot_4,2)."</td><td></td></tr>";
print "\n<tr bgcolor=white onMouseOver=bgColor='silver'; onMouseOut=bgColor='white' style='border:1px solid black;'>";
print "<td ><b>GRAND TOTAL</td><td align=right><b>".number_format($mkhadi_tot_1+$mvip_tot_1,2)."</td><td align=right ><b>".number_format($mkhadi_tot_2+$mvip_tot_2,2)."</td><td align=right><b>".number_format($mkhadi_tot_3+$mvip_tot_3,2)."</td><td align=right><b>".number_format($mkhadi_tot_4+$mvip_tot_4,2)."</td><td></td></tr>";
print "<tr style='border:1px solid black;'><td colspan=3><br>Certified that the stock as per the stock list of</td><td colspan=3><br>Certified that the stock as per the stock list of</td></tr>";
print "<tr style='border:1px solid black;'><td colspan=3>$brrow[1]</td><td colspan=3>$brrow[1]</td></tr>";
print "<tr style='border:1px solid black;'><td colspan=3>has been physically verified by me in the presence of the manager</td><td colspan=3>has been physically verified in my presence and the</td></tr>";
print "<tr style='border:1px solid black;'><td colspan=3>and the rate, quantity and value noted against each item is correct.</td><td colspan=3>rate, quantity and value noted against each item is correct.</td></tr>";
print "<tr style='border:1px solid black;'><td colspan=6><br><br></td></tr>";
print "<tr style='border:1px solid black;'><td colspan=3>Stock Verification Officer</td><td colspan=3>Manager in charge</td></tr>";
print "<tr style='border:1px solid black;'><td colspan=3>Dist Khadi and Village Industries</td><td colspan=3>$brrow[1]</td></tr>";
?>
</table>