<?
session_start();
$brcode = $_SESSION['brcode'];
$user   = $_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out11'); parent.document.location='ind.php'; </script>";
 return;
}
include("opendb.php");
$rsqry=mysqli_query($db,"select distinct jvno,tr_no,j_type from journal2 where brcode='$brcode' and j_type = 'BP' or j_type = 'BR' ") or die(mysqli_error());
while($row=mysqli_fetch_array($rsqry))
{
    $mjvno  = $row[0];
    $refno  = $row[1];
    if($row[2]=='BR')
    {
        $rsqry1=mysqli_query($db,"select j_type,brno from bnkrec where brcode='$brcode' and j_type = '$mjvno' ") or die(mysqli_error());
        $row1=mysqli_fetch_row($rsqry1);
        if($row1[1]!=$refno)
        {
            print " BRNo not matching $refno (from journal), $row1[1] (from Bank Rec) JVNO - $mjvno<br>";
            //mysqli_query($db,"update journal2 set tr_no = '$row1[1]' where brcode='$brcode' and j_type = 'BR' and jvno = $mjvno") or die(mysqli_error());
        }
        else
        {
            //print " BRNo matching $refno (from journal), $row1[1] (from Bank Rec)<br>";
        }
    }
    else if($row[2]=='BP')
    {
        $rsqry1=mysqli_query($db,"select j_type,bpno from bnkpay where brcode='$brcode' and j_type = '$mjvno' ") or die(mysqli_error());
        $row1=mysqli_fetch_row($rsqry1);
        if($row1[1]!=$refno)
        {
            print " BPNo not matching $refno (from journal), $row1[1] (from Bank Pay) JVNO - $mjvno<br>";
            //mysqli_query($db,"update journal2 set tr_no = '$row1[1]' where brcode='$brcode' and j_type = 'BP' and jvno = $mjvno") or die(mysqli_error());
        }
        else 
        {
            //print " BPNo matching $refno (from journal), $row1[1] (from Bank Pay)<br>";
        }
    }
    
}
?>


