<?
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:steelblue;color:white}
.right{text-align:right}
</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><center>[Printed by: <?print $user?> on <?print date("r");?>]</td></tr>
<tr><td><hr></td></tr>
</TABLE>

<?
$tbl="spareinvwar".$brcode;
$qq=mysqli_query($db,"select distinct warno from $tbl order by warno");
while($qrow=mysqli_fetch_array($qq))
{
print "<Fieldset><legend>Warno: ".substr($brcode,0,3).'-'.$qrow[0]."</legend>";
$re=mysqli_query($db,"select * from $tbl where warno='$qrow[0]'");
print "<table cellspacing=1 cellpadding=1 width=100%>";
print "<th>Date<th>Part Name<th>PSN Qty<th>TelcQty<th>Price";
print "<th>Customer<th>MSNO<th>CSSNo <th>STO No<th>In Date <th>STO NO";
print "<th>PH In<br> Date <th>PH Qty<th>PH Stono";
while($tmprow=mysqli_fetch_array($re))
{
 print "<tr bgcolor=aliceblue><td>".datetohtml($tmprow[date])."</td>";
 print "<td>$tmprow[partname]</td>";
 print "<td align=right>$tmprow[psnqty]</td><td align=right>$tmprow[telcqty]</td><td align=right>$tmprow[price]</td>";
$sql="select * from warsparetransout where warno='$tmprow[warno]' and brcode='$brcode'";
$postres=mysqli_query($db,$sql) or die('post err'.mysqli_error($db));
 if(mysqli_num_rows($postres)<=0)
 {
  print "<td colspan=4><font color=red>Not reached at Service Branch</font></td>";
  //continue;
 }
 else{
$warrow=mysqli_fetch_array($postres);
 print "<td>$warrow[cust]</td><td>$warrow[msno]</td><td>$warrow[cssno]</td><td>$warrow[stono]</td>";}
$bname=getbrname($brcode);
 $re2=mysqli_query($db,"select * from sparetrinwar where frombr='$bname' and warno='$qrow[0]'");
 if(mysqli_num_rows($re2)<=0)
 {
  print "<td colspan=2><font color=red>Not transfered to Branch</font></td>";
  //continue;
 }
else{
 $inrow=mysqli_fetch_array($re2);
 print "<td>".datetohtml($inrow[date])."</td><td>$inrow[stono]</td>";
}
 $reph=mysqli_query($db,"select * from sparetrinwarph where frombr='$bname' and warno='$qrow[0]'");
 if(mysqli_num_rows($reph)<=0)
 {
  print "<td colspan=10><font color=red>No Physical Transfer</font></td>";
  continue;
 }
 $inrow=mysqli_fetch_array($reph);
 print "<td>".datetohtml($inrow[invdate])."</td><td>$inrow[psnqty]</td><td>$inrow[stono]</td>";

}
print "</table></fieldset><br>";
}
?>

