<?
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");
?>
<style>

	td,th,body{font-size:15;font-family:'arial narrow';letter-spacing:1}
	th{background-color:silver}
</style>
<center>
<h3>
PSN TELCON <?PRINT $branch?><BR>
RECONCILIATION REPORT (SPARE TRANSFER OUT)</H3>
AS ON
<?
print date('r').' Printed by '.$user;
print "<br>&nbsp;<table cellspacing=1 cellpadding=3 bgcolor='gray'>";
print "<th>Sent to Branch <th>Sent Amount<th>Rec Amount <th>Pending";
// $re=mysqli_query($db,"select distinct to_branch from sparetransout where brcode='$brcode' order by 1")or die(mysqli_error($db));

 $re=mysqli_query($db,"select distinct a.to_branch, b.brname from sparetransout a,branch b where a.brcode='$brcode' and a.to_branch=b.brcode  order by b.brname")or die(mysqli_error($db));
 while($ro=mysqli_fetch_row($re))
 {
   $sq="select sum(qty*amount) from sparetransout where to_branch='$ro[0]' and brcode='$brcode'";
    $res=mysqli_query($db,$sq);
   $amtrow=mysqli_fetch_row($res);
  print "<tr bgcolor='white'><td>".($ro[1])."</td><td align=right>";
  print putComa($amtrow[0])."</td>";

   $sq="select sum(qty*amount) from sparetransin where from_branch='$brcode' and brcode='$ro[0]'";
    $res1=mysqli_query($db,$sq);
   $amtrow1=mysqli_fetch_row($res1);
   print "<td align=right>".putComa($amtrow1[0])."</td>";
  $diff=($amtrow[0]-$amtrow1[0]);
  $tdiff+=$diff;
   print "<td align=right>".putComa(($amtrow[0]-$amtrow1[0]))."</td>";
 }
 print "<tr bgcolor=silver><td colspan=3>Total</td><td align=right>".putComa($tdiff)."</td></tr>";
 print "</table>";
?>

