<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}

include("../opendb.php");
include("../test.php");
$brres=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brrow=mysqli_fetch_array($brres);

?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
th{background-color:lightsteelblue;color:black}
//tr{background-color:white}
</style>
<CENTER>
<TABLE>
<TR><TD COLSPAN=2 ALIGN=CENTER><b> PSN CONSTRUCTION EQUIPMENTS P LTD </b><BR>
	 <?print $brrow[braddr].",".$brrow[brcity].",<br><u> PH - ".$brrow[brphone]?></u>
TIN: <?print $brrow[tin]?>, CST: <?print $brrow[cstno]?>&nbsp;
</td></tr>
<tr><td align=center><font size=3><br><b>CLOSED SALE ORDER REPORT </font>AS ON <?print date("d-m-Y")?></td></tr>
</TABLE>
<br>
<?
$re=mysqli_query($db,"select distinct orderno,date,orderto from saleorder_spare where closed='Y' and brcode='$brcode' order by orderno");
while($ro=mysqli_fetch_array($re))
{
  $res=mysqli_query($db,"select * from saleorder_spare where orderno='$ro[orderno]' and brcode='$brcode' and closed='Y'");
 print "<fieldset><legend><b> Order No: $ro[orderno], Date: ".datetohtml($ro[date]).",";
 print " Customer: $ro[orderto]</b></legend>";
 $i=1;
    print "<table cellspacing=1 cellpadding=3 bgcolor='steelblue' width=100%>";
    print "<th width=15>No <th width=175>Partcode <th>Part Name <th width=55>Ord Qty";
    print "<th width=55>Sup Qty <th width=55>Ext.Qty <th width=55>Reason <th>Date Closed <th>Amount";
$tamt=0;
  while($row=mysqli_fetch_array($res))
  {
    print "\n<tr bgcolor='white'>";
    print "<td>".$i++."</td><td>$row[partcode]</td><td>$row[partname]</td>";
    print "<td align=right>$row[sqty]</td><td align=right>$row[sup_qty]</td>";
    print "<td align=right>$row[qty]</td>";
    print "<td>$row[reas]</td><td>".datetohtml($row[cldate])."</td>";
    $amtres=mysqli_query($db,"select lstprice from spareprmast where partcode='$row[partcode]'");
    $amtrow=mysqli_fetch_row($amtres);
    $amt=$amtrow[0]*$row[sqty];
    $tamt+=$amt;
    print "<td align=right>".putComa($amt)."</td>";
    print "</tr>";
  }
  print "\n<tr><td colspan=8 align=center><font color=white><b>Total</td><td align=right><font color=white>".putComa($tamt)."</td></tr>";
 print "</table></fieldset><br>";
}
?>

<script>
 function clsfun(b,a)
 {
  if(confirm('Short close the item '+a+' ?'))
   document.location='shclssale.php?itcode='+a+'&ordno='+b;
 }
</script>
