<?
session_start();
include("test.php");
include ("opendb.php");
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$typ=$_REQUEST['typ'];
$val=$_REQUEST['val'];
$partic=$_REQUEST['partic'];
$jvno=$_REQUEST['jvno'];
$amt=$_REQUEST['amt'];


$str = preg_replace('/\s+/', '', $partic);
$str = str_replace("-", "", $str);
$str = str_replace(".", "", $str);
$str1=substr($str, 0, 6);
$dyn_tbl='led_'.$str1.$brcode;
$tbl="tmpjournal2".$user;

print $v=("select * from $dyn_tbl where brcode='$brcode' and partic='$partic' and jvno='$jvno' and  sub_jvno='$val' ");
  

  $valid=mysqli_query($db,"select * from $dyn_tbl where brcode='$brcode' and partic='$partic' and jvno='$jvno' and  sub_jvno='$val' ");
  
  $valid1=mysqli_query($db,"select * from ledger_edit where brcode='$brcode' and partic='$partic' and jvno='$jvno' and  sub_jvno='$val' ");
 


   if((mysqli_num_rows($valid)>0)||(mysqli_num_rows($valid1)>0)){
    ?>
    <input type='hidden' name='msg' id='msg' value='0'>
    
   <?}

   else{
	$sql="select * from $tbl where brcode='$brcode' and partic='$partic' and jvno='$val' ";
echo $sql;

	$result=mysqli_query($db,$sql) or die ('Error'.mysqli_error($db));
	$row=mysqli_fetch_array($result);


	 mysqli_query($db,"insert into $dyn_tbl (jvno,partic,sub_jvno,type,amt,j_type,tr_no,brcode) values('$jvno','$partic','$row[1]','$row[2]','$amt','$row[8]','$row[11]','$brcode')");
	
	 	 print $m=("insert into $dyn_tbl (jvno,partic,sub_jvno,type,amt,j_type,tr_no,brcode) values('$jvno','$partic','$row[1]','$row[2]','$amt','$row[8]','$row[11]','$brcode')");
	
	 
     ?>

     <input type='hidden' name='msg' id='msg' value='1'>

     <?

     }
   
   
 	
 ?>
	
