<table  border='1' class='conf_tbl' style="border_collpase:collapse; color:white; ">
<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
include("test.php");
include ("opendb.php");
$flg=$_REQUEST['flg'];

echo $flg;



$typ=$_REQUEST['typ'];
$val=$_REQUEST['val'];
 $partic=$_REQUEST['partic'];
$jvno=$_REQUEST['jvno'];
$subjv=$_REQUEST['subjv'];

$str = preg_replace('/\s+/', '', $partic);
$str = str_replace("-", "", $str);
$str = str_replace(".", "", $str);


$str1=substr($str, 0, 6);
print $dyn_tbl='led_'.$str1.$brcode;
$i=0;
 $sjv = explode(",", $subjv);

 if($flg=='del')
 
 {

   foreach($sjv as $jv2)
   {
 	 if($jv2!='')
 	 {

		print $my=("delete from  $dyn_tbl where sub_jvno='$jv2' and jvno='$jvno'");

		mysqli_query($db,"delete from  $dyn_tbl where sub_jvno='$jv2' and jvno='$jvno'");
		
		mysqli_query($db,"delete from  ledger_edit where sub_jvno='$jv2' and jvno='$jvno'");



		

        }
    }
   echo "<tr><th height=30>Data Has been Deleted successfully !!</th>";
 }

else{

	foreach($sjv as $jv){
 	 if($jv!=''){
  
       mysqli_query($db,"insert into $dyn_tbl select '',jvno,partic,sub_jvno,type,amt,j_type,tr_no,brcode from ledger_edit where sub_jvno='$jv' and jvno='$jvno'");
//$query="insert into   $dyn_tbl select '',jvno,partic,sub_jvno,type,amt,j_type,tr_no,brcode from ledger_edit where sub_jvno='$jv' and jvno='$jvno'";
//echo $query;
     
  	 }
  
	}

  	//mysqli_query($db,"delete from ledger_edit where  jvno='$jvno'");

  	//print  $my=("delete from ledger_edit where  jvno='$jvno'");



	foreach($sjv as $jv1){

  	if($jv1!=''){
  
   
   		mysqli_query($db,"insert into  ledger_edit(jvno,partic,sub_jvno,type,amt,j_type,tr_no,brcode) select jvno,partic,sub_jvno,type,amt,j_type,tr_no,brcode from  $dyn_tbl where sub_jvno='$jv1' and jvno='$jvno'");
   		
	print $my=("insert into  ledger_edit(jvno,partic,sub_jvno,type,amt,j_type,tr_no,brcode) select jvno,partic,sub_jvno,type,amt,j_type,tr_no,brcode from  $dyn_tbl where sub_jvno='$jv1' and jvno='$jvno'");
     

     
  	 }
  
	}


	mysqli_query($db,"drop table $dyn_tbl");
echo "<tr><th height=30 >Data Has been Updated successfully !!</th>";

 }

 echo "<th height=30><input type='image' src='images/ok.png' onclick='window.location.reload();'></th></tr>";

?>
</table>
