<? 
session_start();
include_once('includes/top.php');
include_once("test.php");
include_once('opendb.php');
include_once("includes/function.php");
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
?>
<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form1.css" rel="stylesheet" />
<style>
#txt{
font-family: Arial, Helvetica;
background-color: #F2F2F2;

}
</style>
<style>
 td{font-family:verdana;font-size:14;color:black;}
 th{font-family:verdana;font-size:14;color:white;background-color:#5b5858}
 body{background-color:silver;}
 select
  {border-style:ridge;
   border-color:black;
   height:25px;
   border-size=1;
   font-family:verdana;
   color:black;
  }
 input
  {border-style:ridge;
   border-color:#22437f;
   background-color:white;
   height:25px;
   font-weight:bold;
   border-size=1;
   font-family:sans-serif;
   color:BLACK;
  }
</style>

<?
$us=mysqli_query($db,"select level from bruser where username='$user'")or die(mysqli_error($db));
$r=mysqli_fetch_row($us);
$user_level=$r[0];

$query="select * from prod_invoice where biltpe=3 and brcode='$brcode' group by invno";
$rs=mysqli_query($db,$query);
while($row=mysqli_fetch_array($rs))
{
	$sq="update journal2 set partic='$row[customer]' where partic='CASH' and jvno='$row[jvno]'";
	echo $sq;
	echo "<br>";
	$sqrs=mysqli_query($db,$sq);
  	$jvres=mysqli_query($db,"select max(jvno) from journal2 where brcode='$brcode'");
  	$jvrow=mysqli_fetch_row($jvres);
        if($jvrow[0]>0)
		{
                	$jvno=($jvrow[0]+1);
		}
	$sumqry=mysqli_query($db,"select sum(nettot) from prod_invoice where invno='$row[invno]' and brcode='$brcode'");
	$sumrw=mysqli_fetch_array($sumqry);
	$sql1="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type) values('$row[invdate]','$jvno','Dr','Cash','$sumrw[0]','0.00','Amount Received aganist credit.','$brcode','CR')";
	mysqli_query($db,$sql1);
	echo $sql1;
	echo "<br>";
	$sql2="insert into journal2(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type) values('$row[invdate]','$jvno','Cr','$row[customer]','0.00','$sumrw[0]','Amount Received aganist credit.','$brcode','CR')";
	mysqli_query($db,$sql2);
	echo $sql2;
	echo "<br>";
}


?>

