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

$sql="select tr_no,sum(qty*amount),brcode,jvno from sparetransout group by tr_no,brcode order by brcode ";
$re=mysqli_query($db,$sql);
$i=1;
while($trrow=mysqli_fetch_array($re))
{
  $jvres=mysqli_query($db,"select cramt from journal2 where jvno='$trrow[jvno]' and brcode='$trrow[brcode]'");
  $jvrow=mysqli_fetch_array($jvres);
  if($jvrow[0]!=$trrow[1])
  { $sql="update journal2 set dramt='$trrow[1]' where type='Dr' and jvno='$trrow[jvno]' and brcode='$trrow[brcode]'";
   print '<br>'.$sql;
$sql="update journal2 set cramt='$trrow[1]' where type='Cr' and jvno='$trrow[jvno]' and brcode='$trrow[brcode]'";
   print '<br>'.$sql;
 }

//  print "<br>".$i++.". amt in spretr $trrow[0]:".$trrow[1]."amt in jv:$trrow[jvno] :".$jvrow[0]." brcode:".$trrow[brcode];
}
?>
