<?
session_start();
include("../opendb.php");
include("../test.php");
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
.noprint, .print {display:none;}
@media screen {
.noprint, .printns {display:block;}
.print {display:none;}
}
@media print {
.print {display:block;}
.noprint, .printns, {display:none;}
}
	th{background-color:steelblue;color:white}
	td{font-size:12}
.right{text-align:right}
</style>
<center>
<h3>SPARE INVOICE REPORT - GROUP WISE</H3>
<form action='<?Print $PHP_SELF?>' method='post'>
<table cellspacing=1 cellpadding=1 bgcolor='steelblue'>
<tr><td bgcolor='white' align=center>
<table class=noprint>
<tr><td>Date from </td><td>dd <input type=text name='d1' size=2 value='<?print date("d")?>'>
mm <input type=text name='m1' size=2 value='<?print date("m")?>'>
yy <input type=text name='y1' size=4 value='<?print date("Y")?>'></td></tr>

<tr><td align=right>to </td><td>dd <input type=text name='d2' size=2 value='<?print date("d")?>'>
mm <input type=text name='m2' size=2 value='<?print date("m")?>'>
yy <input type=text name='y2' size=4 value='<?print date("Y")?>'>
</td></tr>
<tr><td colspan=2 align=center bgcolor='lightsteelblue'><input type=submit value='Show' name='show'></td></tr>
</table>
</td></tr>
</table>
</form>

<?
if($show)
{
 $dfrom=$y1.'-'.$m1.'-'.$d1;
 $dto=$y2.'-'.$m2.'-'.$d2;

$invre=mysqli_query($db,"select distinct invtype from spareinvoice where brcode='$brcode'");
while($invrow=mysqli_fetch_array($invre))
{
 print "<fieldset><legend> Type $invrow[0] from ".datetohtml($dfrom).' to '.datetohtml($dto)."</legend>";
  $sql="select distinct group1 from partmaster";
  $grre=mysqli_query($db,$sql);
  while($grrow=mysqli_fetch_array($grre))
  {
/*    if($brcode=='ERA153')
    $sql="select a.partcode,sum(qty)sqty,sum(aprice)sparice,a.partname,sum(taxamt)stx,sum(cessamt)ces,sum(tot)tt from spareinvoice a,partmaster b where a.partcode=b.partcode and b.group1='$grrow[0]' and entrydate>='$dfrom' and entrydate<='$dto' group by a.partcode order by b.group1";
    else*/
    $sql="select a.partcode,sum(qty)sqty,sum(aprice)sparice,a.partname,sum(taxamt)stx,sum(cessamt)ces,sum(tot)tt from spareinvoice a,partmaster b where a.partcode=b.partcode and b.group1='$grrow[0]' and a.entrydate>='$dfrom' and a.entrydate<='$dto' and a.brcode='$brcode' group by a.partcode order by b.group1";

    $invre=mysqli_query($db,$sql) or die('Err:'.mysqli_error());
   
    print "<table border=1 width=100%><th colspan=7>Group : $grrow[0]</th></tr>";
    print "<tr><th width=20>No<th>Part Name <th>Quantity <th>Amount<th>Tax <th>Cess <th>Total";
    $tqty=0;
    $tapr=0;
    $tstx=0;
    $tces=0;
    $ttot=0;
     $i=1;
    while($invrow=mysqli_fetch_array($invre))
    {
      print "\n<tr><td>".$i++."</td><td width=width=450>$invrow[partcode]</td><td align=right>$invrow[1]</td>";
      print "<td align=right>$invrow[2]</td><td align=right bgcolor='ivory'>$invrow[stx]</td>";
      print "<td align=right>$invrow[ces]</td><td align=right>$invrow[tt]</td></tr>";
    $tqty+=$invrow[sqty];
    $tapr+=$invrow[sparice];
    $tstx+=$invrow[stx];
    $tces+=$invrow[ces];
    $ttot+=$invrow[tt];
    }
    print "<tr bgcolor='lightsteelblue'><td>&nbsp;</td><td align=center><b>Total</td>";
    print "<td align=right><b>".putComa($tqty)."</td><td align=right><b>".putComa($tapr)."</td>";
    print "<td align=right bgcolor='ivory'><b>".putComa($tstx)."</td>";
    print "<td align=right><b>".putComa($tces)."</td><td align=right><b>".putComa($ttot)."</td></tr>";
    print "</table><br>";
  }
 print "</fieldset><br>";
}
} //  end if
?>
