<?
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>
GOODS IN TRANSIT (SPARE TRANSFER OUT)</H3>
AS ON
<?
print date('r').' Printed by '.$user;
$brre=mysqli_query($db,"select brcode,brname from branch order by brname");
while($brrow=mysqli_fetch_array($brre))
{
print "<fieldset> <legend>$brrow[brname]</legend>";
print "<table cellspacing=1 cellpadding=3 bgcolor='gray' width=80%>";
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());

 $re=mysqli_query($db,"select distinct a.to_branch, b.brname from sparetransout a,branch b where a.brcode='$brrow[brcode]' and a.to_branch=b.brcode  order by b.brname")or die(mysqli_error());
 while($ro=mysqli_fetch_row($re))
 {
   $sq="select sum(qty*amount) from sparetransout where to_branch='$ro[0]' and brcode='$brrow[brcode]'";
    $res=mysqli_query($db,$sq);
   $amtrow=mysqli_fetch_row($res);

   $sq="select sum(qty*amount) from sparetransin where from_branch='$brrow[brcode]' and brcode='$ro[0]'";
    $res1=mysqli_query($db,$sq);
   $amtrow1=mysqli_fetch_row($res1);
    $diff=($amtrow[0]-$amtrow1[0]);
    $tdiff+=$diff;
  if($diff>0)
 {
  print "<tr bgcolor='white'><td>".($ro[1])."</td><td align=right>";
  print putComa($amtrow[0])."</td>";

   print "<td align=right>".putComa($amtrow1[0])."</td>";
   print "<td align=right><a href='vmreconmd.php?br=$brrow[0]' target=x>".putComa(($amtrow[0]-$amtrow1[0]))."</a></td>";
}
 }
print "<tr bgcolor=silver><td colspan=3>Total</td><td align=right>".putComa($tdiff)."</td></tr>";
$gtdiff+=$tdiff;
$tdiff=0;
print "<tr bgcolor='silver'><td colspan=3>Warranty Pending </td>";
$tbl="spareinvwar".$brrow[0];
$sq="select sum(price) from $tbl where psnqty>0 and trans='n'";

$re1=mysqli_query($db,$sq);
$re1row=mysqli_fetch_row($re1);
print "<td align=right><a href='vmwar.php?br=$brrow[0]' target='a'>".$re1row[0]."</a></td></tr>";
print "</table> ";
$gtdiff+=$re1row[0];

print "</fieldset>";
}// end while
print "Grand Total Rs.".putComa($gtdiff);
?>

