<?
session_start();
include("../opendb.php");
include("../test.php");
if($show)
{
$dfrom=$y1.'-'.$m1.'-'.$d1;
 $dto=$y2.'-'.$m2.'-'.$d2;
$re=mysqli_query($db,"select distinct(invno),invtype,entrydate,customer,addr,tin,paytype from spareinvoice where brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto' order by invno")or die(mysqli_error($db));
//$row=mysqli_fetch_array($re)or die("Fetch Error:".mysqli_error($db));
while($row=mysqli_fetch_array($re))
{
$brres=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brrow=mysqli_fetch_array($brres);
?>
<style>
th{font-size:13}
</style>
<style>
 td,body{font-family:'arial narrow';font-size:15;letter-spacing:1}
</style>

<center>

<table width=100% BORDER=0>
<tr><td>Invoice No :
<?
print '['.substr($brcode,0,3).']';
?>
 S-<?

if($foc=='foc') 
print "FOC ";
print $row[invno];
print $row[paytype];
?>
</td><td align=right>Date : <?print datetohtml($row[entrydate])?> </td>

<TD COLSPAN=2 ALIGN=CENTER> FORM <?print $row[invtype]?> (<?print $row[paytype]?> Invoice)</td>
<TR><TD COLSPAN=2 ALIGN=left> Customer : <?print $row[customer].'<br>'.$row[addr].'<br>TIN : '. $row[tin]?></td></tr>
</table>

<table border=0 cellspacing=1 cellpadding=0 WIDTH=90%>
<th width=15>NO.<th style="text-align:left">Location<th width=210 style="text-align:left">DESCRIPTION OF GOODS <TH width=40>QUANTITY <TH width=50>RATE <th width=80>DIS% <th width=80>AMOUNT  
<?
 if($row[vatorcst]=='VAT')
   print "<TH>VAT (12.5%)";
 else
   print "<th>CST";
?>
<th>CESS(1%) <TH>NET AMOUNT</TH>
<tr><td colspan=10><hr></td></tr>
<?
//$re1=mysqli_query($db,"select * from spareinvoice where invno='$invno' and invtype='$invtype' and brcode='$brcode'")or die('ERr'.mysqli_error($db));

 $sql="select * from spareinvoice where invno='$row[invno]' and brcode='$brcode' and invdate>='$dfrom' and invdate<='$dto'";
$re1=mysqli_query($db,$sql)or die('err:'.mysqli_error($db));

$i=1;
$tq=0;
$tp=0;
$cnt=1;
while($row1=mysqli_fetch_array($re1))
{
if($row1[tot]<=0)
{
 print "<script> alert('Invalid Entry Total')</script>";
 print "<h1>Error</h1>";
}
if($row1[taxamt]<=0)
{
 print "<script> alert('Invalid Entry Tax')</script>";
 print "<h1>Error</h1>";
}
if($row1[cessamt]<=0)
{
 print "<script> alert('Invalid Entry Cess')</script>";
 print "<h1>Error</h1>";
}
 print "<tr><td align=center width=15>".$cnt++."</td>";
 $locres=mysqli_query($db,"select location from sparelocmast where brcode='$brcode' and itemcode='$row1[partcode]'");
 $locrow=mysqli_fetch_row($locres);
print "<td>$locrow[0]</td>";
 PRINT "<td>$row1[partcode] ($row1[partname])</td><td align=right>$row1[qty]</td><td align=right>".putComa($row1[price])."</td>";
print "<td align=center>$row1[disc]</td>";
print "<td align=right>".putComa($row1[aprice])."</td>";
print "<td align=right>$row1[taxamt]</td>";
print " <td align=right>$row1[cessamt]</td>";
print "<td align=right>".putComa($row1[tot])."</td></tr>";
//print "<tr><td colspan=10><hr></td></tr>";
$i++;
$tq+=$row1[qty];
$tp+=$row1[tot];
$tamount+=($row1[aprice]);
$tvat+=$row1[taxamt];
$tcess+=$row1[cessamt];
}

for($j=$i;$j<=16;$j++)
{
 //print "<tr><td colspan=10>&nbsp;</td></tr>";
}

print "<tr><td colspan=110>";

print "<HR></tD></tR>";

print "<tr><td align=right>Total </td><td></td><td align=right>$tq Nos</td>";
print "<td></td><td></td><td align=right>".putComa($tamount)."</td>";
print "<td align=right>".putComa($tvat)."</td>";
print "<td align=right>".putComa($tcess)."</td>";
print "<td colspan=6 align=right>".putComa($tp)."</td></tr>";
$rnd=round($tp);
$rnd2=round(($tp-$rnd),2);
if($rnd2!=0)
{
  print "<td colspan=8 align=right>Rounded ".putComa(abs($rnd2))."</td>";
  $gtot=($tp-$rnd2);
  print "<td colspan=9 align=right><b>Grand Total = $gtot</td>";
}
else
 $gtot=$tp;

print "<tr><td colspan=160>";
for($j=0;$j<=100;$j++)
{
// print "=";
}
//print "</td></tr>";

//print "<tr><td colspan=3>Amount Chargeable (In Words)</td><td colspan=17 align=right>E. & O.E</td></tr>";
$tt= str_replace(',','',number_format($gtot,2));


log_entry($brcode,$user,$REMOTE_ADDR,"Print spareinvoice:$row[invno] , inv type: $invtype");
?>
</table>
<?
}
}
?>

<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
//	tr{background-color:white}
	th{background-color:steelblue;color:white}
	td{font-size:13}
.right{text-align:right};
</style>

<center>
<h3>SPARE INVOICE (SHORT) REPORT -2</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>



