<?
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 distinct(jvno) from journal2 where brcode='$brcode' order by jvno  limit 1000";
$re=mysqli_query($db,$sql)or die(mysqli_error());
print "<table border=1>";

while($row=mysqli_fetch_array($re))
{


$i=0;
$sql=mysqli_query($db,"select jvno from spareinvoice where brcode='$brcode' and jvno='$row[jvno]'");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td>spare invoice More than one jv</td></tr>";
}

}

$sql=mysqli_query($db,"select jvno from warspareinvoice where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td>war spare More than one jv</td></tr>";
}
}

$sql=mysqli_query($db,"select jvno from sparepurchase where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td>spare purchase More than one jv</td></tr>";
}
}

$sql=mysqli_query($db,"select jvno from sparetransout where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;

if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td> trans out More than one jv</td></tr>";
}

}

$sql=mysqli_query($db,"select jvno from sparetransin where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td>tran in More than one jv</td></tr>";
}
}

$sql=mysqli_query($db,"select j_type from cshrec where brcode='$brcode' and j_type='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td>csh recMore than one jv</td></tr>";
}
}

$sql=mysqli_query($db,"select j_type from cshpay where brcode='$brcode' and j_type='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
}

$sql=mysqli_query($db,"select j_type from bnkrec where brcode='$brcode' and j_type='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td> bnkrec More than one jv</td></tr>";
}
}

$sql=mysqli_query($db,"select j_type from bnkpay where brcode='$brcode' and j_type='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td> bnkpay More than one jv</td></tr>";
}
}

$sql=mysqli_query($db,"select jvno from veh_invoice where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td>veh inv More than one jv</td></tr>";
}
}

$sql=mysqli_query($db,"select jvno from journal2 where brcode='$brcode' and jvno='$row[jvno]' and j_type='jv' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td> journal2 More than one jv</td></tr>";
}
}


$sql=mysqli_query($db,"select jvno from salesreturn where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td> s retrn More than one jv</td></tr>";
}

}

$sql=mysqli_query($db,"select jvno from jobcard where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td>jobcard More than one jv</td></tr>";
}
}


$sql=mysqli_query($db,"select jvno from sparepurreturn where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td>purch ret More than one jv</td></tr>";
}
}

$sql=mysqli_query($db,"select jvno from warsparetransout where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;

if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td> war spr More than one jv</td></tr>";
}
}


$sql=mysqli_query($db,"select jvno from veh_purchase where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
}

$sql=mysqli_query($db,"select jvno from veh_purchreturn where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;

if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td>veh p ret More than one jv</td></tr>";
}
}

$sql=mysqli_query($db,"select jvno from veh_salereturn where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td> veh s ret More than one jv</td></tr>";
}
}

$sql=mysqli_query($db,"select jvno from veh_transin where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td>veh trans in More than one jv</td></tr>";
}
}

$sql=mysqli_query($db,"select jvno from veh_transout where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td>veh tr out More than one jv</td></tr>";
}
}

$sql=mysqli_query($db,"select jvno from crnote where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;

if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td> cr note More than one jv</td></tr>";
}
}

$sql=mysqli_query($db,"select jvno from item_purchase where brcode='$brcode' and jvno='$row[jvno]' ");
  if(mysqli_num_rows($sql)>0)
{
$i++;
if ($i>1) 
{
    print "<tr><td>$row[0]</td><td>$i</td><td>item purch More than one jv</td></tr>";
}
}
//if ($i==1) 
//{
//    print "<tr><td>$row[0]</td><td>$i</td><td>OK</td>";
//}



if ($i==0) 
{
   print "<tr><td>$row[0]</td><td>$i</td><td>no jv at all</td></tr>";

}

}
print "</table>";
?>
