<?
 session_start();
 
 $brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];

$branch=$_SESSION['branch1'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;font-size:13}
th{background-color:c1d799}
.mnu{margin-left:5}
body{BACKGROUND-COLOR:fcfff1}
</style>
<H3>ITEM PURCHASE REGISTER</H3>
<form action='<?print $PHP_SELF?>'>
<table bgcolor='silver'>
<tr><td> Date from </td><td>dd<input type=text name='d' size=2 value='<?print date("d",time())?>'>
				mm<input type=text name='m' size=2 value='<?print date("m",time())?>'>
				yy<input type=text name='y' size=4 value='<?print date("Y",time())?>'>
			</td></tr>

<tr><td> To </td><td>dd<input type=text name='d1' size=2 value='<?print date("d",time())?>'>
				mm<input type=text name='m1' size=2 value='<?print date("m",time())?>'>
				yy<input type=text name='y1' size=4 value='<?print date("Y",time())?>'>
			</td>
</tr>
<tr><td colspan=2 align=center><input type=submit name='show' value='Show'>
<input type=submit value='Print' name='prn'></td></tr>
</table>
</form>
<?

$y=$_REQUEST['y'];
$m=$_REQUEST['m'];
$d=$_REQUEST['d'];
$y1=$_REQUEST['y1'];
$m1=$_REQUEST['m1'];
$d1=$_REQUEST['d1'];

$prn=$_REQUEST['prn'];
$show=$_REQUEST['show'];


if($prn)
{
   $df=$y.'-'.$m.'-'.$d;
   $dt=$y1.'-'.$m1.'-'.$d1;
       print "<script> window.open('prnitmreg.php?df=$df&dt=$dt');</script>";
}
 if($show)
  {
   $df=$y.'-'.$m.'-'.$d;
   $dt=$y1.'-'.$m1.'-'.$d1;
   $tq=$tuni=$ttax=$tgtot=$tnet=0;

   $re=mysqli_query($db,"select * from item_purchase_veh where curdate>='$df' and curdate<='$dt' and brcode='$brcode'");
    if(mysqli_num_rows($re)>0)
    {
     print "<table bgcolor=silver cellspacing=1 cellpadding=3 width=100%>";
     print "<th>P.No <th>Entry Date<th>Bill Date<th>Item <th>Description<th> Unit Amt. <th>Qty <th> Tax Amt <th>Tax% <th>Cess Amt.";
     print "<th> Net Amt.<th>P.Inv. <th>Supplier<th>GSTNO";
        while($row=mysqli_fetch_array($re))
       {
   $ss=mysqli_query($db,"select partname from partmaster where partcode='$row[item_code]'");
  $itrow=mysqli_fetch_array($ss);
//print "select supname,gstno from sup_master where icode='$row[sup]'";
   $ss=mysqli_query($db,"select supname,cst from sup_master where icode='$row[sup]'");
  $srow=mysqli_fetch_array($ss);

   print "<tr bgcolor='white'><td align=center>$row[pno]</td>";
   print "<td>".implode('-', array_reverse(explode('-', $row['curdate'])))."</td><td>".implode('-', array_reverse(explode('-', $row['pdate'])))."</td>";
   print "<td>$row[item_code]</td><td>$itrow[partname]</td>";
   print "<td align=right>$row[net]</td><td align=center>$row[qty]</td>";
   print "<td align=right>$row[taxamt]</td><td align=right>$row[taxp]</td><td align=right>$row[cessamt]</td><td align=right>$row[gross]</td><td align=right>$row[purinvoice]</td>";
   print "<td>$srow[supname]</td><td>$srow[cst]</td>";
  $tq+=$row['qty'];
  $tuni+=$row['gross'];
  $ttax+=$row['taxamt'];
  $tgtot+=$row['cessamt'];
  $tnet+=$row['net'];
  }
   print "<tr><td colspan=3 align=center><b>Total </td><td align=right>".putComa($tnet)."</td>";
   print "<td align=center>".($tq)."</td>";
   print "<td align=right>".putComa($ttax)."</td>";
   print "<td> &nbsp; </td><td align=right>".putComa($tgtot)."</td>";
   print "<td align=right>".putComa($tuni)."</td>";

   
 }
}
?>


