<?
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'];


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



$str1=substr($str, 0, 6);
print $dyn_tbl='led_'.$str1.$brcode;

  $sql=mysqli_query($db,"select * from journal2 where brcode='$brcode' and partic='$partic' and  jvno='$jvno'  ");
  
print $s=("select * from journal2 where brcode='$brcode' and partic='$partic' and  jvno='$jvno'  ");
  
  if($jvno=='opb'){

               $sql=mysqli_query($db,"select drcr as type,op  from ledger where brcode='$brcode' and led='$partic' ");
   }
   
  
  $result=mysqli_query($db,"select * from $dyn_tbl where brcode='$brcode' and  jvno='$jvno'  ");
  
  print $r=("select * from $dyn_tbl where brcode='$brcode' and  jvno='$jvno'  ");
  


   $result1=mysqli_query($db,"select * from ledger_edit where brcode='$brcode' and partic='$partic' and  jvno='$jvno'  ");


  $row=mysqli_fetch_array($sql);

  if($row['type']=='Dr'){
  
    $tit='Debit';
    $sub_tit='Credit';
    $amt=$row['dramt'];
   
      
   }

   if($row['type']=='Cr'){
  
    $tit='Credit';

    $sub_tit='Debit';
    $amt=$row['cramt'];
   }
 
      
?>     

      <table  border='1' class='conf_tbl' style="border_collpase:collapse;width:180px;background-color:white;font-size:4px; ">

       <tr><th colspan='4'><? echo $partic;?></th><th><input type="image" src="images/close.png"  id='close'  onclick='close_div();'/></th><tr>
<?

  if($jvno=='opb'){
  
   $amt=$row[1];
   print"<tr><td colspan='5'>Opening Balance</th><tr>";
  }
  else{

     print"<tr><td colspan='5'>Journal:".$jvno."</th><tr>";
   
   }
   ?>
 
       <tr><th colspan='5'> <? echo $tit;?></th><tr>
       <tr><td colspan='5'> <? echo $amt;?></td><tr>
       <tr><th colspan='5'> <? echo $sub_tit;?></th><tr>
      <tr><th>Type<th>J_Type<th>Tr_no<th>Amount<th></tr>
   <?
     $total=0;
      $flg=1;

     if(mysqli_num_rows($result1)>0){

     print "<tr><td colspan='5'> Already Exists</td><tr>";
     }

  
  while($row2=mysqli_fetch_array($result1))
       {

      print" <tr><td>".$row2['type']."<td>".$row2['j_type']."<td>".$row2['tr_no']."<td>".$row2['amt']."</td><td>";
?>
       <input type='checkbox'  onclick="conf_filter('<? echo $row2[3];?>',this);"></td></tr>
<?
   
     $total+=$row2['amt'];
        
	$flg++;
     }
       

    

       print "<tr><td colspan='5'> New Entries</td><tr>";

       if(mysqli_num_rows($result)<1){

            print "<tr><td colspan='5'><small>No results found... </small></td><tr>";
       }

	while($row1=mysqli_fetch_array($result))
       {

      print" <tr><td>".$row1['type']."<td>".$row1['j_type']."<td>".$row1['tr_no']."<td>".$row1['amt']."</td><td>";
?>
       <input type='checkbox'   onclick="conf_filter('<? echo $row1[3];?>',this);"></td></tr>
<?
   
     $total+=$row1['amt'];
        
	$flg++;
     }
 ?>
<tr><td colspan='3' >Total</td><td align='right'><? echo putcoma($total);?></td><td></td></tr>
<tr><th colspan='5' id=?submitbttn? ><input type='button' name='save' id='svbttn' value='Uppdate' onclick="upd_led('<? echo $jvno; ?>','conf');"/>
<input type='button' name='save' id='delbttn' value='Delete' onclick="upd_led('<? echo $jvno; ?>','del');"/></th></tr>
</table></form>
	
